I am trying to create simple page to display content of the table (customer: id, first_name, last_name) with Symfony + doctrine. I created GS\OrderBundle\Entity\Customer with columns and getters/setters. Created route for it. I want to create a view , something like:
<table>
{% for c in form %}
{% set id = c.get('value') %}
<tr>
<td>{{ form_widget(c) }}</td>
<td>{{ c[id].firstName }}</td>
<td>{{ c[id].lastName }}</td>
</tr>
{% endfor %}
</table>
and Controller to pass the values from the customer table to this view. I am trying something like:
namespace GS\OrderBundle\Controller;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Bundle\FrameworkBundle\Controller\Controller;
use GS\OrderBundle\Entity\Customer;
use Doctrine\ORM\EntityManager;
class CustomerListController extends Controller
{
public function listAction()
{
$repository = $this->getDoctrine()
->getRepository('GSOrderBundle:Customer');
$customer = $repository->findAll();
$form = $this->createFormBuilder($customer)->getForm();
return $this->render(
'customerTable.html.twig',
array('form' => $form->createView())
);
return new Response($names);
}
}
On the symfony website I found only examples with setting data or outputing single row data. Could you please provide any simple example how to display content of the table in the view?