简体   繁体   中英

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.

{% 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:

<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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM