Jonah
Jonah

Reputation: 16202

Clear Session flash after setFlash has been called?

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

Upvotes: 3

Views: 6983

Answers (3)

CodeOwl
CodeOwl

Reputation: 672

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.

Upvotes: 0

od3n
od3n

Reputation: 314

i use this instead of above code.

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

Upvotes: 5

starlocke
starlocke

Reputation: 3661

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

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

Upvotes: 14

Related Questions