我可以在我的createdAt
视图中显示所有其他表格的show
字段。代码是
{% block body %}
<div class="row">
<div class="col-md-12">
<h1>{{ title }}</h1>
<small>Criado {{ notes.createdAt | date('d/m/Y') }}</small>
{% if notes.updatedAt != notes.createdAt %}
<small>Editado {{ notes.updatedAt | date('d/m/Y') }}</small>
{% endif %}
</div>
</div>
...
showAction
public function showAction($id)
{
return $this->render('note/show.html.twig', array(
'notes' => $this->getDoctrine()->getRepository('CDGBundle:Note')->findAllByBudget($id),
'title' => 'Notas do cliente ' . $id
));
}
findAllByBudget
方法是在存储库中创建的:
public function findAllByBudget($id)
{
$qb = $this->createQueryBuilder('n');
return $qb
->orderBy('n.id', 'DESC')
->where(
$qb->expr()->eq('n.budget', '?1')
)
->setParameter(1, $id)
->getQuery()
->getResult();
}
不知怎的,我只是在显示这个特定的实体时遇到了问题。
答案 0 :(得分:3)
你会得到一系列音符,所以在twig模板中你必须使用一些循环来显示每个音符。例如:
<div class="col-md-12">
<h1>{{ title }}</h1>
{% for note in notes %}
<small>Criado {{ note.createdAt | date('d/m/Y') }}</small>
{% if note.updatedAt != note.createdAt %}
<small>Editado {{ note.updatedAt | date('d/m/Y') }}</small>
{% endif %}
{% endfor %}
</div>