3

I am working through the "Cake PHP 1.3 Application Development Cookbook," CH. 1 -- the section "Allowing logins with username or email".

The problem is that when you login using your email, even if you are successful, the flash message for an "Invalid Account" has already been set by the Auth component. So I need to unset that message in the login action of the users controller, after a successful login by email. Setting it to the empty string does not work, as an empty orange bar is displayed.

Is there a way to completely unset a flash message?

Thanks, Jonah

2
  • 2
    It shouldn't output that message if the login is correct. Are you sure your code is right? Can you post what you have written in your UserController/AppController referring to the login part?
    – linkyndy
    Jun 4, 2011 at 21:05
  • I hit the EXACT same problem in the book, I'm glad I found your post!
    – ActionOwl
    Dec 16, 2011 at 20:05

3 Answers 3

14

To unset a flash message with CakePHP 1.3, using the SessionComponent within a controller:

$this->Session->delete('Message.flash');
1
5

i use this instead of above code.

$this->Session->delete('Message.auth');
0

If you're worried about the message persisting in memory after the Session->flash() function has been called in the view, then you needn't. Inside the flash() function, the message is getting cleared out with the this call:

CakeSession::delete('Message.' . $key);

So you shouldn't need to delete the message yourself.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.