Render another view and pass variables to it

Hello everyone. Could somebody please explain me how to render another view from a controller and pass data to it. Another question. I am wondering if I do something like

$this->response->redirect('');

in a controller. Is there a way to somehow pass data to that view that I am redirecting a user to? Is it possible to do only with session or any other ways are possible.



7.2k

You could use the dispatcher to forward control onto another action

http://docs.phalconphp.com/en/latest/reference/controllers.html#dispatch-loop

You could pick a new view http://docs.phalconphp.com/en/latest/reference/views.html#picking-views and set the variables as you would normally

http://docs.phalconphp.com/en/latest/reference/views.html#transfer-values-from-the-controller-to-views

This won't redirect the url though. However if you are intent on redirecting, I would suggest storing the vars in a session bag and then retrieving them on the new controller (checking if they are set), Once these have been assigned to new variables in the view, delete them from the session.

More info at http://docs.phalconphp.com/en/latest/reference/session.html