How to install and display flash messages in symfony1.4
I am creating a login form where I have to set a flash message if login fails. I used the following code to set up a flash message. In actions.class.php inside this function is called executeLogin_process
$this->getUser()->setFlash('error', 'Invalid User Name or Password', false);
$this->redirect('login/index');
and display the message in indexSuccess.php
<?php if ($sf_user->hasFlash('error')): ?>
<div class="flash_error"><?php echo $sf_user->getFlash('error') ?></div>
<?php endif ?>
Using this I am unable to display error messages. I don't know if I am using the correct code or not. Anyone please help me ...
source to share
Don't use the third parameter in the setFlash method.
This will work:
$this->getUser()->setFlash('error', 'Invalid User Name or Password');
See: http://www.symfony-project.org/api/1_4/sfUser#method_setflash
If the third parameter is set to false. flash msg won't be saved to pass the redirect.
source to share
setFlash ($name, $value, $persist)
$ persist true if the flash should persist for the next request (true by default)
Why did you set the third parameter to false
?
$this->getUser()->setFlash('error', 'Invalid User Name or Password', true);
And the third parameter is the default true
, so just:
$this->getUser()->setFlash('error', 'Invalid User Name or Password');
source to share