Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to redirect after create action in SF2 controller
    primarykey
    data
    text
    <p>Here is the action that is not working properly, The entity is created but i'm always rendering the AileronsFrontendBundle:Default:observation.html.twig</p> <p>As the code shows, this createAction should render my home template, but the template rendering is not the good one.</p> <pre><code> /** * Creates a 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-&gt;createForm(new ObservationType(), $entity); $form-&gt;bind($request); if ($form-&gt;isValid()) { $entity-&gt;getObservator()-&gt;setIp($request-&gt;getClientIp()); $em = $this-&gt;getDoctrine()-&gt;getManager(); $em-&gt;persist($entity); $em-&gt;flush(); $msg = array( 'type'=&gt;'success', 'title'=&gt;'Merci !', 'text'=&gt;'Votre observation à bien été enregistré, merci pour votre participation !', ); $this-&gt;redirect($this-&gt;generateUrl('home', array('msg'=&gt;$msg))); } return array( 'entity' =&gt; $entity, 'form' =&gt; $form-&gt;createView(), ); </code></pre> <p>Insted of redirect i've tried this:</p> <pre><code>$this-&gt;render('AileronsFrontendBundle:Default:index.html.twig', array('msg'=&gt;$msg)); </code></pre> <p>It is not working too.</p> <p>Here is my index action</p> <pre><code>/** * @Route("/", name="home") * @Template() */ public function indexAction() { return array(); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload