GOA
GOA

Reputation: 91

cakephp custom flash layout error

i have looked at the documentatioin of cakephp 2.5.4 about custom flash messages and some other tutorials on how to make this but its not working

i have error.ctp and success.ctp under elements folder error.ctp

<div id="error-flash">
    <?php echo h($message); ?>
</div>

success.ctp

<div id="success-flash">
    <?php echo h($message); ?>
 </div>

and in controller i call them like this

$this->Session->setFlash(__(' file successfully uploaded.','success',array('class'=>"flash_msg_ok")));

$this->Session->setFlash(__('Upload Failed','error',
                array("class" => "flash_msg_error")));

my chrome developer tools still shows the default flash generated. its not rendering the element or applying the specified classes

i've also tried this

$this->Session->setFlash('success','default',array('class'=> 'success'))

still nothing.

of note is that am using custom layout and css for the page. what am i missing here?

Upvotes: 0

Views: 479

Answers (1)

Ella Ryan
Ella Ryan

Reputation: 1155

There are a couple of issues..

First, you've accidentally put the other function variables inside the translation string. You can fix the call as follows (note closing bracket moved to end of message string):

$this->Session->setFlash(__(' file successfully uploaded.'),'success',array('class'=>"flash_msg_ok"));

$this->Session->setFlash(__('Upload Failed'),'error',
            array("class" => "flash_msg_error"));

Second, you'll need to add the class to your custom error element file (the cakephp docs neglect to mention this!). For example:

<div id="error-flash" class="<?php echo $class; ?>">
    <?php echo h($message); ?>
</div>

Hope that helps!

Upvotes: 0

Related Questions