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

mindyourapp
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
reguille
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..
mindyourapp
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
francky06l
<?php echo $message?> in your default.ctp is more appropriate
francky06l
sorry in your flash.ctp ..oupsss
mindyourapp
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)
francky06l
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 :-)
Kalt
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 :
/app/views/layout/message_success.ctp

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

2- Notice flash message layout :
/app/views/layout/message_notice.ctp

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

3- Error flash message layout :
/app/views/layout/message_error.ctp

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

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');
}
else
{
$this->Session->setFlash('Something wrong !', 'message_error');
$this->redirect('edit/'.$id, null, true);
}[/PHP]

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]
mindyourapp
Interesting... thanks for helping, I'll take this thread as a guide later biggrin.gif
Frank
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
karo
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:

CODE
           
               ...

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


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



flash_success.ctp:

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


(similar for flash_error.ctp)


...but in result i only get:

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



what's wrong here?

thanx!
coroner05
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.
marshalrosy
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
ianmcn
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-2014 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.