Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Redirect from embedded controller

Tags:

php

symfony

I use embedded controller to render form that's used on multiple pages:

Twig

{% render 'Bundle:Controller:someForm' %}

Controller

public function someFormAction()
{
    // Some logic

    ...

    if ($form->isValid()) {

        ...

        $this->get('session')->setFlash('successful', "Woey!");

        return $this->redirect($this->generateUrl('homepage'));
    }

    return $this->render('Bundle:Template:form.html.twig', array('form' => $form->createView()));
}

I need to redirect back to homepage after the form was successfully submitted as a part of post-redirect-get design pattern. If I use it as I described above, I'll get exception as response from embedded controller was 302 instead of 200 (at least I expect it works like this).

Is it possible to redirect normally in such scenario? Or am I approaching the situation (with form that's rendered on multiple pages) from totally wrong angle?

like image 267
Ondrej Slinták Avatar asked Aug 08 '11 15:08

Ondrej Slinták


1 Answers

Just to make it official answer, Fabien doesn't think Symfony2 will ever support this feature.

like image 68
Ondrej Slinták Avatar answered Nov 03 '22 15:11

Ondrej Slinták