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 session - 1.2.0

Hello,

It seems that using 1.2.0, flashSession is not keept after redirect. Please advice.

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

    $di['flashSession'] = function(){
        return new \Phalcon\Flash\Session(array(
                'error' => 'alert alert-error',
                'success' => 'alert alert-success',
                'notice' => 'alert alert-info',
        ));
    };

public function A() { $this->flashSession->success('You did it !'); $this->response->redirect('b'); }

public function B() { print_r($this->flashSession->getMessages()); // Will have no messages }

For me it works

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

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

in \views\controllerName\actionName.phtml

<div id="messages"><?php $this->flashSession->output() ?></div>

Calin try to use in your posts ` php your code `



98.9k

Return the response object or disable the view rendering:

public function A()
{
    $this->flashSession->success('You did it !');
    return $this->response->redirect('b');
}
public function A()
{
    $this->flashSession->success('You did it !');
    $this->view->disable();
    $this->response->redirect('b');
}


51.1k

@Phalcon, it is working as you suggested. Thank you.