We have moved our forum to GitHub Discussions. For questions about Phalcon v3/v4/v5 you can visit here and for Phalcon v6 here.

FlashSession not outputting when setMainView() is being used in indexAction of your controller

I am using

$this->view->setMainView("myview");

in my indexAction of my Controller.

When I try to set a message

$this->flashSession->message("test","test_message");

and then disable my view

$this->view->disable();

and redirect to another page

return $this->response->redirect("desired_url");

it doesn't render at all. No output.

However, if I disable the setMainView and allow the view to normally render on my index.phtml page using

$this->getContent();

the FlashSession works as expected.

This is either a bug or a design flaw. I am not sure which. Anyone else experience this? Maybe I am missing sometthing here...

You must log in first to vote

In this case you need to manually print the messages in the corresponding view:

<p><?php $this->flashSession->output() ?></p>

or

{{ flashSession.output() }}

Taken from https://docs.phalcon.io/en/latest/reference/flash.html

Hi Jimmy, thank you for your response, however, I have already tried that. That is how it is output when I don't set the Main View. When I do

$this->setMainView("newView");

the output has nothing.