CakePHP自定义flash消息 [英] CakePHP customize flash message

查看:233
本文介绍了CakePHP自定义flash消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通常, $ this-> Session-> setFlash(__('My message。'));



将输出:

 < div id =flashMessageclass =message> 
我的消息。
< / div>

如何更改,所以它会输出:

 < p class =notification> 
我的邮件。
< / p>

解决方案

如果你看看源代码你会看到SessionComponent方法的第二个参数是一个元素的名称:

  function setFlash($ message, $ element ='default',$ params = array(),$ key ='flash')

您可以使用以下内容在例如'flash_notification.ctp'



的视图/元素(或Views / Elements for Cake2)中创建一个文件:

 < p class =notification> 
<?php echo $ message;?>
< / p>

并使用

  $ this-> Session-> setFlash(__('My message。'),'flash_notification'); 


Normally, the $this->Session->setFlash(__('My message.'));

Will output:

<div id="flashMessage" class="message">
    My message.
</div>

How can I change that, so it'll output:

<p class="notification>
    My message.
</p>

instead?

解决方案

If you look at the source code you will see that the second parameter of the SessionComponent method is the name of an element:

function setFlash($message, $element = 'default', $params = array(), $key = 'flash')

You can create a file in views/elements (or Views/Elements for Cake2) called for instance 'flash_notification.ctp'

with the following content:

<p class="notification">
  <?php echo $message; ?>
</p>

and use

$this->Session->setFlash(__('My message.'), 'flash_notification');

这篇关于CakePHP自定义flash消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆