Reputation: 3063
i am creating a login form in which i have to set a flash message if login fails. i have used the following code to set flash message. In actions.class.php inside that a function called executeLogin_process
$this->getUser()->setFlash('error', 'Invalid User Name or Password', false);
$this->redirect('login/index');
and to 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 ?>
By using this i am not able to display the error messages.i don't know whether i am using the right code or not. Any one please help me...
Upvotes: 4
Views: 10227
Reputation: 1
If you remove flash message:
$this->getUser()->setFlash('error', NULL);
If you use a success page or layout, then do $sf_user->setFlash('error', NULL)
Upvotes: 0
Reputation: 160843
setFlash ($name, $value, $persist)
$persist true if the flash have to persist for the following request (true by default)
Why did you set the 3rd parameter to false
?
$this->getUser()->setFlash('error', 'Invalid User Name or Password', true);
And the 3rd parameter is default true
, so just:
$this->getUser()->setFlash('error', 'Invalid User Name or Password');
Upvotes: 2
Reputation: 1931
Dont use the third parameter on your 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. the flash msg will not persisted to pass a redirect.
Upvotes: 9