所以我有一个数组,其中包含正在传递给 twig 的帖子,Twig 将从那里使用 for 循环输出数组中的每个帖子。我希望每个帖子都有一个删除按钮,其 url 附有该帖子的 id 所以在我的 for 循环中我有这样的东西:
{% for post in Posts %}
<div class="yellBox">
<div class="col-sm-2">
<img class="square yellBoxImage" src="https://pbs.twimg.com/profile_images/637255421099536384/dkLZc90x.jpg" alt="Avatar" />
</div>
<div class="yellBody col-sm-10">
<h4><strong>{{ User.name }}</strong><span class="yellDate">- {{ post.created_at }}</span></h4>
<p>
{{ post.body }}
</p>
// other buttons
//the delete button in question
<a href="{{ path_for('deleteYell')}}/{{ post.id }}"><button type="button" name="button">Delete</button></a>
<div id="test">
</div>
</div>
</div>
{% endfor %}
{{ path_for('deleteYell')}}/{{ post.id }}
这向我抛出一个错误,指出 url 末尾缺少信息,这意味着帖子.id 部分在/
我的路线如下:
$this->delete('/yell/{id}', 'UserController:deleteYell')->setName('deleteYell');
我应该做哪些更改才能使其正常工作?
最佳答案
关于php - 使用 Twig 模板引擎为具有所需占位符 (/post/{id} ) 的路由动态创建链接,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40701218/