Miloš Miloš - 13 days ago 6
PHP Question

Symfony2 - How to render a view from another controller

I have two controllers, homepage and Security.

In the homepage, I am displaying one view and in the security, I am doing some things, and one of them is the email address validation.

What I would like is that when the email validation code is not valid, display the homepage with a flash message. For that, I will have to render the indexAction of the HomepageController, from the Security controller, by giving him as parameter the flash message.

How can this be done? Can I render a route or an action from another controleller?

Thank you in advance.

Answer

I have found the solution, simply use the forward function by specifying the controller and the action nanme:

return $this->forward('MerrinMainBundle:Homepage:Index', array('flash_message'=>$flash_message));