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


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

3 answers

Don't use the third parameter in the setFlash method.
This will work:

$this->getUser()->setFlash('error', 'Invalid User Name or Password');



If the third parameter is set to false. flash msg won't be saved to pass the redirect.



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




If you delete the flash message:

$this->getUser()->setFlash('error', NULL);


If you are using success page or layout then do $sf_user->setFlash('error', NULL)



All Articles