Affichage du rendu d'un template
Bonjour,
Débutant avec Symfony2, je me rapproche de vous pour une information.
En effet, j'ai un contrôleur disposant de la méthode render() pour l'affichage du template twig.
Code:
1 2 3 4 5 6 7 8 9
|
public function afficherTousAction() {
$em = $this->getDoctrine()->getManager();
$producteur = $em->getRepository('VignobleProducteurBundle:Producteur')
->afficherTous();
$em->flush();
return $this->render('VignobleProducteurBundle:Vignoble:index.html.twig', array("producteur" => $producteur));
} |
Code:
1 2 3 4 5 6 7 8 9
|
class ProducteurRepository extends EntityRepository {
public function afficherTous() {
return $this->getEntityManager()
->createQuery('SELECT p FROM VignobleProducteurBundle:Producteur p ORDER BY p.pseudo ASC')->getResult();
}
} |
Code:
1 2 3 4 5 6 7 8
|
<!DOCTYPE html>
<head></head>
<body>
{% for producteur in producteurs %}
<li>{{ producteur }}</li>
{% endfor %}
</body> |
J'ai le message d'erreur
Code:
Variable "producteurs" does not exist in VignobleProducteurBundle:Vignoble:index.html.twig at line 4
Comment résoudre ce problème car je ne voit pas comment procéder?
Merci d'avance.
Transact.