Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
VCJeroen opened this issue Jul 28, 2015 · 4 comments
Closed

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

VCJeroen opened this issue Jul 28, 2015 · 4 comments

Comments

@VCJeroen
Copy link

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" }

@renatogabrielbr
Copy link
Contributor

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));

@virgofx
Copy link
Contributor

virgofx commented Aug 3, 2015

@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.

@renatogabrielbr
Copy link
Contributor

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

@VCJeroen
Copy link
Author

VCJeroen commented Aug 4, 2015

@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 VCJeroen closed this as completed Aug 4, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants