CakePHP - 更改默认Flash布局 [英] CakePHP - Changing default Flash layout
本文介绍了CakePHP - 更改默认Flash布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我知道我可以通过在Elements文件夹中创建 custom_flash.ctp
来替换flash标记,并调用它:
I know that I can replace the flash markup by creating something like custom_flash.ctp
in Elements folder and call it like:
$this->Session->setFlash('Hello', custom_flash)
但是,如何在不添加第二个参数时使用自定义布局?
But how can I use custom layout when not adding the second parameter?
$this->Session->setFlash('Hello')
我想我可以通过在Elements文件夹中有一个名为 default.ctp
的文件来替换默认值。但我不能。
I thought I can replace the default by having a file named default.ctp
inside Elements folder. But I can't.
我想保持代码尽可能短。这是为什么我正在寻找一种方法来做这个
I want to keep the code as short as possible. That's why I'm looking a way to do this
任何解决方案?感谢
推荐答案
尝试创建您的组件:
class MySessionComponent extends Session {
public function setFlash($message) {
return $this->setFlash($message, 'custom_flash');
}
}
>
and than in your controller just use:
public $components = array('MySession');
$this->MySession->setFlash('Hello');
这篇关于CakePHP - 更改默认Flash布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文