symfony - How to redirect after create action in SF2 controller -
here action not working properly, entity created i'm rendering aileronsfrontendbundle:default:observation.html.twig
as code shows, createaction should render home template, template rendering not one.
/** * creates new observation entity. * * @route("/observation/new", name="observation_create") * @method("post") * @template("aileronsfrontendbundle:default:observation.html.twig") */ public function createaction(request $request) { $entity = new observation(); $form = $this->createform(new observationtype(), $entity); $form->bind($request); if ($form->isvalid()) { $entity->getobservator()->setip($request->getclientip()); $em = $this->getdoctrine()->getmanager(); $em->persist($entity); $em->flush(); $msg = array( 'type'=>'success', 'title'=>'merci !', 'text'=>'votre observation à bien été enregistré, merci pour votre participation !', ); $this->redirect($this->generateurl('home', array('msg'=>$msg))); } return array( 'entity' => $entity, 'form' => $form->createview(), );
insted of redirect i've tried this:
$this->render('aileronsfrontendbundle:default:index.html.twig', array('msg'=>$msg));
it not working too.
here index action
/** * @route("/", name="home") * @template() */ public function indexaction() { return array(); }
you need return redirect.
return $this->redirect($this->generateurl('home', array('msg'=>$msg)));
an action needs return response object. example returning rendered twig file:
return $this->render('acmetestbundle:test:test.html.twig', array());
Comments
Post a Comment