Thursday, April 1, 2010

Re: Custom flash messages

This is how I use flash()

AppController:
public function flash($msg, $url = null, $layout = null)
{
$this->Session->setFlash($msg, (is_null($layout) ? 'flash_msg' :
$layout));

if (!is_null($url))
{
$this->redirect($url);
exit(0);
}
}

I have several flash layouts: flash_error, flash_msg, flash_success,
etc. All of the containing divs have ID flash_msg.

javascript (jQuery):

$(function()
{
showFlashMsg();
});


function showFlashMsg()
{
$('#flash_msg').hide().center({top: 10})
.animate({opacity: 'show'}, 'normal', function()
{
/* don't fade out errors
*/
if (!$(this).hasClass('error-message'))
{
$(this).fadeOut(8000);
}
})
.find('a.HideFlash').click(function(e)
{
$('#flash_msg').hide();
e.preventDefault();
});
}

Check out this article:

http://www.jamesfairhurst.co.uk/posts/view/custom_cakephp_flash_messages_updated


On Apr 1, 1:35 am, Ed Propsner <crotchf...@gmail.com> wrote:
> I've been playing around trying to customize my flash messages with CSS and
> I'm having a bit of trouble.
>
> I tried to define the class with the message itself  ....
>
> [code]    $this->Session->setFlash(__(' Some Flash message here ',
> array('class' => 'flash_failure')));    [/code]
>
> I also tried to use the example in the CookBook and create separate .ctp
> files in the layouts folder and defining the views that way but that didn't
> seem to work either.
>
> The message shows up fine in the view but it shows as plain text and no CSS
> style.

Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions.

You received this message because you are subscribed to the Google Groups "CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en

To unsubscribe, reply using "remove me" as the subject.

No comments: