Pergunta
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?
Solução
I've cleared cache ... and now everything seems to be OK.
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow