如何在我的symfony链接中添加ID?(how to add a ID in my symfony links?)

系统教程 行业动态 更新时间:2024-06-14 17:03:54
如何在我的symfony链接中添加ID?(how to add a ID in my symfony links?)

我对symfony中的链接系统有疑问。

我使用这样的普通链接:

<a href="{{ path('my_path')}}">click me</a>

然后在控制器中,相应的动作如下:

/** * @Route("/my_path", name="my_path") * @Template() */ public function myAction() { ...

现在,我在列表中有这个链接,我需要为每个添加一个item.id 所以控制器看起来像:

/** * @Route("/my_path/id", name="my_path") * @Template() */ public function myAction($id) { ...

所有这一切都在一个循环中:

{% for item in items %} <a href="{{ path('my_path')}}">click me</a> <br> {% endfor %}

如何将item.id添加到路径中?

i have a question about the linking system in symfony.

I use normal links like this:

<a href="{{ path('my_path')}}">click me</a>

and then in the controller the corrosponding action looks like:

/** * @Route("/my_path", name="my_path") * @Template() */ public function myAction() { ...

now, i have this links in a list and i need to add a item.id to each. so the controller looks like:

/** * @Route("/my_path/id", name="my_path") * @Template() */ public function myAction($id) { ...

and all of this is in a loop:

{% for item in items %} <a href="{{ path('my_path')}}">click me</a> <br> {% endfor %}

how to add the item.id into the path?

最满意答案

找到解决方案:

{% for item in items %} <a href="{{ path('my_path', {'id': item.id})}}">click me</a> <br> {% endfor %}

found the solution:

{% for item in items %} <a href="{{ path('my_path', {'id': item.id})}}">click me</a> <br> {% endfor %}

更多推荐

本文发布于:2023-04-24 14:17:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/dzcp/82e7ea002449bb52b00f5237cf041656.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:链接   如何在   symfony   links   ID

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!