[Custom Repository] Comment récupérer une entité ?
Bonjour !
Je cherche a recuperer une entite dans mon champs de formulaire traite par une requete dans mon Custom Repo.
Je precise que le render de cette fonction est une include dans un autre template twig.
Le probleme, c'est que je ne recoit qu'un array au lieu d'une entitee oO
Je vous poste mes sources :)
Mon Custom Repo :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
|
<?php
namespace Luna\KBundle\Repository;
use Doctrine\ORM\EntityRepository;
class SidRepository extends EntityRepository
{
public function retrieveByName($idusr)
{
/**
* Creer la requete a l'envers, Sid vers Utilisateurs
*
*
/**
* Sid -> Site -> Crew -> Users -> Utilisateurs
*/
*/
return $this->createQueryBuilder('s')
->leftJoin('s.site', 'si')
->leftJoin('si.crew', 'c')
->leftJoin('c.users', 'u')
->leftJoin('u.utilisateur', 'ut')
->where('ut = ?1')
->setParameter(1, $idusr)
}
} |
Ma Fonction dans mon Controlleur :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32
|
public function chooseAction($idusr)
{
$em = $this->getDoctrine()->getEntityManager();
$entities = $em->getRepository('LunaKBundle:Sid')->retrieveByName($idusr);
$request = $this->getRequest();
if (!$entities) {
throw $this->createNotFoundException('Je ne trouve pas la Sid entity dans choose.');
}
$showForm = $this->createForm(new SidSelect(), $entities);
if ('POST' === $request->getMethod()) {
$showForm->bindRequest($request);
if ($showForm->isValid()) {
$em = $this->getDoctrine()->getEntityManager();
$em->persist($entities);
$em->flush();
return $this->redirect($this->generateUrl('Sid_choix', array('id' => $entities->getId())));
}
}
return $this->render('LunaKBundle:Sid:choose.html.twig', array(
'entities' => $entities,
'form_choose' => $showForm->createView(),
));
} |
Mon render include dans le template twig :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
|
{% extends '::layout.html.twig' %}
{% block content %}
<h1>Planter une graine</h1>
Donner un nom a la graine que vous souhaitez planter.
<form action="{{ path('Sid_init', {'idusr': app.user.id}) }}" method="post" {{ form_enctype(form) }}>
{{ form_widget(form) }}
<p>
<button type="submit">Creer</button>
</p>
</form>
Si votre graine est deja plante, choisissez un type d'objet a lui ajouter
(A voir plus tard :P)
{% render 'LunaKBundle:Sid:choose' with {'idusr' : app.user.id} %}
{% endblock %} |