Warning: Illegal string offset '_imagedir' in /home/cakephpf/public_html/lofiversion/index.php on line 545

Warning: Illegal string offset '_emodir' in /home/cakephpf/public_html/lofiversion/index.php on line 546
CakePHP UnOfficial Community Forum > How to change flash() layout?
Help - Search - Member List - Calendar
Full Version: How to change flash() layout?
CakePHP UnOfficial Community Forum > Layouts and Design

The title says it all. I wanted to change the default layout of the $this->flash() message. The default one is too empty and naked. And I also found out that the default flash() layout doesn't have the title tags, so the ugly document address is displayed on the title bar --> not nice!

Can't figure out how to change that. Any ideas? ph34r.gif
Create a template file called flash.ctp (or flash.thtml if you're using 1.1), design it however you want, then place it under the layouts folder. It will override the default flash() template found in /cake/libs/view/templates/layouts

I guess that would work..
I did like what you said but <?php echo $content_for_layout; ?> didn't seem to output the message that i've stated in $this->flash('message','/'); ?> ...
did i missed something? unsure.gif
<?php echo $message?> in your default.ctp is more appropriate
sorry in your flash.ctp ..oupsss
Oh.. so it's $message now for flash(); ..it worked! thanks a bunch guys!

(ps: why can't they just use $content_for_layout? .. bleargh... tongue.gif)
The reason is that you can echo the flash message in the default layout, having 2 variables with same name for different content is likely not working :-)
You can even go further by customizing your flash messages, according to the nature of its meaning. I have 3 different flash message layouts :

1- Success flash message layout :

[PHP]<div class="message mssg_success">
<div class="mssg_txt">
<?php e($content_for_layout); ?>

2- Notice flash message layout :

[PHP]<div class="message mssg_notice">
<div class="mssg_txt">
<?php e($content_for_layout); ?>

3- Error flash message layout :

[PHP]<div class="message mssg_error">
<div class="mssg_txt">
<?php e($content_for_layout); ?>

To use one of them in my controller, I give the name of the .ctp file I want for the message layout to the function "setFlash" :

[PHP]if ($this->Something->save($this->data))
$this->Session->setFlash('Update done.', 'message_success');
$this->Session->setFlash('Something wrong !', 'message_error');
$this->redirect('edit/'.$id, null, true);

The last thing you have to do is to put this line somewhere in your default layout, to see a flash message when there is one to display :

[PHP]<?php $session->flash(); ?>[/PHP]
Interesting... thanks for helping, I'll take this thread as a guide later biggrin.gif
QUOTE (Kalt @ Nov 5 2007, 11:34 AM)
You can even go further by customizing your flash messages, according to the nature of its meaning. I have 3 different flash message layouts...

I also use this design but i integrated the script.aculo.us scripts for fading in and fading out the messages that users only have to notice but are not realy important, like your success message. Just for a nice web 2.0 touch biggrin.gif
i have a different problem: i get the flash message displayed, but i can't make it pull layouts to format it.

i also use varying formats approach, for success and error messgaes.
but i only get default html formatting, without my custom layouts added around.

TimelineFindingsController class:


$this->layout = 'cms';

if ($saveSuccess) {
$this->Session->setFlash(__('The Finding has been saved', 'flash_success'));
               $this->redirect(array('action' => 'cms_edit', $this->TimelineFinding->id));
} else {
               $this->Session->setFlash(__('The Finding could not be saved. Check for error messages and try again.', 'flash_error'));

cms.ctp: (main layout)

<div id="mainArea"><?php if ($session->flash()) echo "<br />"; ?>
   <?php echo $content_for_layout ?>


<div class="flash flash_success">
<?php echo $content_for_layout; ?>

(similar for flash_error.ctp)

...but in result i only get:

<div id="flashMessage" class="message">The Finding has been saved</div>

what's wrong here?

I have tried to follow your instructions but I have some bad errors there which I couldn't understand. I will post the screenshot of that soon.
I have followed all the instruction and it is pretty well. Yeah there were few logical errors but that we can change on our own
Hi Karo

You've made the same mistake I had, but I've just solved it. Your element parameter is given as a second parameter for the __() localisation function, not a second parameter for the setFlash function.

You put:
[PHP]$this->Session->setFlash(__('The Finding has been saved', 'flash_success'));[/PHP]

It should be:
[PHP]$this->Session->setFlash(__('The Finding has been saved'), 'flash_success');[/PHP]

Note the position of the brackets.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2015 Invision Power Services, Inc.
Lo-Fi 1.1 iDS Beta, Originally written by Matt,
re-written by Shaun Harrison, Layer 04.com, for pre IPB2.0 versions.