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 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63
|
<?php
namespace Europe\VoyageBundle\Services\Voyage;
use Doctrine\ORM\EntityManager;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\Component\HttpFoundation\RedirectResponse;
use Symfony\Component\Routing\RouterInterface;
use Symfony\Component\Form\FormFactory;
class RechercheManager {
private $em;
private $req;
private $ri;
private $ff;
private $form;
public function __construct(EntityManager $em, RequestStack $req, RouterInterface $ri, FormFactory $ff)
{
$this->em=$em;
$this->req=$req->getCurrentRequest();
$this->ri=$ri;
$this->ff=$ff;
}
public function setForm($formType, $recherche, $url=null)
{
$form=$this->ff->create($formType,$recherche);
if ($this->req->getMethod() === 'POST')
{
$form->bind($this->req);
if ($form->isValid())
{
$this->em->persist($recherche);
$this->em->flush();
if (!$url==null)
$this->redirect($url, $recherche);
//La méthode redirect est écrite ci dessous
}
}
$this->form=$form;
}
public function getForm()
{
return $this->form->createView();
}
protected function redirect($url, $recherche)
{
$url=$this->ri->generate($url, array('id'=>$recherche->getId()));
//L'url est bien généré mais c'est ceci qui ne fonctionne pas :
return new RedirectResponse($url);
}
} |
Partager