cphalcon icon indicating copy to clipboard operation
cphalcon copied to clipboard

[2.0.0]+ \Flash\Session getMessages() removes all messages

Open VCJeroen opened this issue 11 years ago • 4 comments

Using the getMessages() without the $remove parameter or with it set to true removes all flash messages, regardless of the $type parameter passed with it. To me it looks like a return of Issue 1575, more or less.

Here's some example code:

use Phalcon\Mvc\Controller;

class TestController extends Controller
{
    public function testAction()
    {
        $this->flash->error('test1');
        $this->flash->success('test2');

        var_dump($this->flash->getMessages('error', false));
        var_dump($this->flash->getMessages('success'));
        var_dump($this->flash->getMessages('error'));

        die;
    }
}

This returns:

array(1) { [0]=> string(5) "test1" } array(1) { [0]=> string(5) "test2" } array(0) { }

instead of the expected:

array(1) { [0]=> string(5) "test1" } array(1) { [0]=> string(5) "test2" } array(1) { [0]=> string(5) "test1" }

VCJeroen avatar Jul 28 '15 08:07 VCJeroen

Does not remove only the type error, you must also pass on success false, and retrieve only error again, This should work var_dump($this->flash->getMessages('success', false));

renatogabrielbr avatar Aug 01 '15 09:08 renatogabrielbr

@tidytrax That will work. I have to admit I came across the same issue and thought the expected behavior would filter flash messages based on type, but after testing for a few seconds, realized it did not.

This really isn't an issue, it's currently the expected behavior, but it's a common pitfall.

Perhaps at a minimum the PHPDOC blocks / documentation could be updated for these methods to explain this distinction a little bit better.

virgofx avatar Aug 03 '15 14:08 virgofx

I agree my Messages implementation only erase the Key (error,warning,info, success) Besides that framework is beaultiful but its getting better !! And really is just missing the DOC for it, because its not a bug.

Hope that i help

renatogabrielbr avatar Aug 03 '15 16:08 renatogabrielbr

@virgofx

I have to admit I came across the same issue and thought the expected behavior would filter flash messages based on type

This was the case in earlier versions of Phalcon (up to and including 1.3.4), but apparently it changed with the release of Phalcon 2.0.0. We only found out about this after upgrading and our code stopped working.

This change is not listed in the changelog hence I assumed it was a bug. Apparently it's not, so I will close the issue.

VCJeroen avatar Aug 04 '15 09:08 VCJeroen