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

Flash doesn't show after Response->redirect

I am setting the flash and then redirecting and no message is showing up. Here is the code:

$this->flash->success('Your comment is saved');
return $this->redirect('forum/show/'.$forum_post_id);

And the redirect function is:

protected function redirect($uri){
        $response = new \Phalcon\Http\Response();
        return $response->redirect($uri);
}

Am I doing something wrong?

Did you register session in your application?

    $di->set('session', function(){
        $session = new Phalcon\Session\Adapter\Files();
        $session->start();
        return $session;
    });


7.9k

Sorry that I didn't mention it - I am using a modified INVO app and the code for registering the session is exactly as yours. By the way if I use $this->dispatcher->forward the message is showing.



98.9k

Are you using Phalcon\Flash\Session instead of Phalcon\Flash\Direct?



7.9k

I am using Phalcon\Flash\Direct:

$di->set('flash', function(){
        return new Phalcon\Flash\Direct(array(
            'error' => 'alert alert-error',
            'success' => 'alert alert-success',
            'notice' => 'alert alert-info',
        ));
    });

If I start using Phalcon\Flash\Session this should solve my problem - thanks!