树枝有什么问题吗?
这是我使用 symfony 2.0 的第一步,所以请原谅一个基本问题。我尝试扩展自动生成的原始代码。在 postcontroller 中我添加了:
/**
* Prints a Post entity.
*
* @Route("/print", name="post_print")
* @Template()
*/
public function printAction()
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('AcmeBlogBundle:Post')->findAll();
echo "<pre>";
print_r($entities);
echo "</pre>";
return array('entities' => $entities);
}
创建了 print.html.twig:
<h1>Post list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Polish</th>
<th>English</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('post_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.polish }}</td>
<td>{{ entity.english }}</td>
<td>{% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif%}</td>
<td>
<ul>
<li>
<a href="{{ path('post_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('post_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('post_new') }}">
Create a new entry
</a>
</li>
<li>
<a href="{{ path('post_print') }}">
Drukuj
</a>
</li>
</ul>
并且我得到了:
AcmeBlogBundle:Post:print.html.twig 第 7 行中不存在变量“entity” 500 内部服务器错误 - Twig_Error_Runtime
知道可能出了什么问题吗?
This is my first steps in symfony 2.0, so please apologise a basic question. I try to extend automaticaly generated crud code. To postcontroller I've added:
/**
* Prints a Post entity.
*
* @Route("/print", name="post_print")
* @Template()
*/
public function printAction()
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('AcmeBlogBundle:Post')->findAll();
echo "<pre>";
print_r($entities);
echo "</pre>";
return array('entities' => $entities);
}
created print.html.twig:
<h1>Post list</h1>
<table class="records_list">
<thead>
<tr>
<th>Id</th>
<th>Polish</th>
<th>English</th>
<th>Date</th>
<th>Actions</th>
</tr>
</thead>
<tbody>
{% for entity in entities %}
<tr>
<td><a href="{{ path('post_show', { 'id': entity.id }) }}">{{ entity.id }}</a></td>
<td>{{ entity.polish }}</td>
<td>{{ entity.english }}</td>
<td>{% if entity.date %}{{ entity.date|date('Y-m-d H:i:s') }}{% endif%}</td>
<td>
<ul>
<li>
<a href="{{ path('post_show', { 'id': entity.id }) }}">show</a>
</li>
<li>
<a href="{{ path('post_edit', { 'id': entity.id }) }}">edit</a>
</li>
</ul>
</td>
</tr>
{% endfor %}
</tbody>
</table>
<ul>
<li>
<a href="{{ path('post_new') }}">
Create a new entry
</a>
</li>
<li>
<a href="{{ path('post_print') }}">
Drukuj
</a>
</li>
</ul>
and I'm getting:
Variable "entity" does not exist in AcmeBlogBundle:Post:print.html.twig at line 7
500 Internal Server Error - Twig_Error_Runtime
Any idea what could be wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我已经清除了缓存...现在一切似乎都正常。
I've cleared cache ... and now everything seems to be OK.