如何在我的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 %}更多推荐
发布评论