[英]How to load database values to the table in symfony2?
I want to update table from values which are stored in the database. 我想从存储在数据库中的值更新表。 I have included this code snippet in the controller file.
我已在控制器文件中包含此代码段。
$emanager=$this->getDoctrine()->getManager();
$repository= $emanager->getRepository('AcmeDemoBundle:ExamTry');
$students= $repository->findAll();
return $this->render('AcmeDemoBundle:Principal:Results.html.twig',
array('students'=>$students));
I have included below code in the html twig. 我在html树枝中包含了以下代码。
{% for student in students%}
<tr>
<th>Head1</th>
<th>Head2</th>
<th>Head3</th>
<th>Head4</th>
<th>Head5</th>
</tr>
{%endfor%}
When I render this code I could get no result. 当我渲染这段代码时,我无法获得任何结果。 I really grateful some one can answer to solve this problem.
我真的很感谢有人可以解决这个问题。 Thank you
谢谢
Use something like this in your Twig: 在您的Twig中使用以下内容:
<table>
<thead>
<tr>
<th>Head1</th>
<th>Head2</th>
<th>Head2</th>
</tr>
</thead>
<tbody>
{% for student in students %}
<tr>
<td>{{ student.field1 }}</td>
<td>{{ student.field2 }}</td>
<td>{{ student.field3 }}</td>
</tr>
{% endfor %}
</tbody>
</table>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.