Issue with \Phalcon\Flash\Session

Hi, i just updated to 3.1.2 and am testing and updating code to match. Was using 2.x before hand. Its also on a windows dll.

Having a issue with the flash.output() in the volt not clearing messages anymore on each load.

$di->set('flash', function(){
    $flash = new \Phalcon\Flash\Session(array(
        'error' => 'alert alert-danger',
        'success' => 'alert alert-success',
        'notice' => 'alert alert-info',
        'warning' => 'alert alert-warning',
    ));
    if (method_exists($flash, 'setAutoescape')) { $flash->setAutoescape(false); }
    return $flash;
});

the above is my flash message setup, now during my tests i tried a few things, the below ill write what worked and what didnt. All test were done in my IndexController, indexAction.

WORKED:

$this->flashSession->output(true);
$this->flash->output(true);
echo "<pre>"; print_r($_SESSION);
exit();
$this->flashSession->output();
$this->flash->output();
echo "<pre>"; print_r($_SESSION);
exit();

DIDNT WORK:

$this->flash->output(true);
echo "<pre>"; print_r($_SESSION);
exit();
$this->flashSession->output(true);
echo "<pre>"; print_r($_SESSION);
exit();
$this->flash->output();
echo "<pre>"; print_r($_SESSION);
exit();
$this->flashSession->output();
echo "<pre>"; print_r($_SESSION);
exit();

Also as a side note, not related to the issue directly. How come the flashSession di is avaliable when not directly defined by me?



243

With doing more testing, I have discovered this also works.

$this->flash->output();
$this->flash->output();
echo "<pre>"; print_r($_SESSION);
exit();


243

More testing, this does not work. It just shows the messages twice and never clears the session

{{ flash.output() }}
{{ flash.output() }}

Are you using FactoryDefault as di? From: https://docs.phalconphp.com/en/3.0.2/reference/flash.html

Usually the Flash Messaging service is requested from the services container. If you’re using Phalcon\Di\FactoryDefault then Phalcon\Flash\Direct is automatically registered as “flash” service and Phalcon\Flash\Session is automatically registered as “flashSession” service

I could be wrong (I haven't used Flash that much yet) but can't / shouldn't you just call flash.clear() to clear those messages?



243

Are you using FactoryDefault as di? From: https://docs.phalconphp.com/en/3.0.2/reference/flash.html

Usually the Flash Messaging service is requested from the services container. If you’re using Phalcon\Di\FactoryDefault then Phalcon\Flash\Direct is automatically registered as “flash” service and Phalcon\Flash\Session is automatically registered as “flashSession” service

I could be wrong (I haven't used Flash that much yet) but can't / shouldn't you just call flash.clear() to clear those messages?

i did not realise it was it was auto loaded in the new version. I will try a couple of things along that line of thought, In the meantime calling

{{ flash.clear() }}

did not work either



243

Im using this in my index.php

$application = new \Phalcon\Mvc\Application($di);
echo $application->handle()->getContent();

{{ flash.clear() }} won't do anything because {{ }} is the Volt short-hand to echo a value. Try using {% flash.clear() %} and see if that works



243

{{ flash.clear() }} won't do anything because {{ }} is the Volt short-hand to echo a value. Try using {% flash.clear() %} and see if that works

no luck just threw a error, Syntax error, unexpected token IDENTIFIER(flash) in...

I don't have a project with Volt template at the moment but I'll do some tests on my personal project when I get home. I had no issue setting a Flash message in a controller and rendering it once in a PHTML file just now. Calling flash->output() twice only gave me one message.

I'll post back when I've had a chance to check it out.



243

Just built a completely basic application to see if i can reproduce the error on a small system, nothing. So it must be related to something else.



243

Ok, so i think i might have found the culprit. Just dont know why its causing the issue.

$this->view->setVar('_SESSION', $_SESSION);

I have that set up in my base controller, For some reason thats causing the issue discribed. I comment it out and the problem resolves. I just do not know why it would cause the issue.



243

Renaming the setVar name doesnt help either. if the $_SESSION is set to thew view it just doesnt work as expected.



243

More testing, more weird results. If i add to the session variable like this

$_SESSION['_flashMessages']['error'][] = "Unable to save";

before the messages display on the current page load it will clear the errors as expected. But if you add to the session and refresh a different page, so seperate page load, it doesnt clear the messages.