Twitter bootstrap 自定义authError消息类
我正在寻找关于如何定制authError消息类的建议(我正在使用Twitter引导,因此希望使用引导中的警报样式) 在/Controller/AppController.php中,我有以下代码段:Twitter bootstrap 自定义authError消息类,twitter-bootstrap,cakephp,Twitter Bootstrap,Cakephp,我正在寻找关于如何定制authError消息类的建议(我正在使用Twitter引导,因此希望使用引导中的警报样式) 在/Controller/AppController.php中,我有以下代码段: public function beforeFilter() { //Set custom authError message if user tries to access a controller when not logged in $this->Auth->authErro
public function beforeFilter() {
//Set custom authError message if user tries to access a controller when not logged in
$this->Auth->authError = __('You are not authorized to view this page.');
}
生成此HTML(class=“message”):
您无权查看此页面。
我想要输出的是这个HTML(class=“alert-alert-danger”):
您无权查看此页面。
非常感谢,可以通过
AuthComponent::$flash
属性配置与Auth组件相关的flash消息
可以在params
键中配置class
属性:
$this->Auth->flash['params']['class'] = 'alert alert-danger';
另见
链接到cookbok在布局中尝试此功能
echo $this->Session->flash('flash', array('params'=>array('class'=>'alert alert-danger')));
请始终提及您的确切CakePHP版本!你是绝对正确的-在我今天早上看到你的回复之前,我意识到我没有提到CakePHP的版本或使用的引导程序-但是非常感谢你的建议。非常感谢。好的,那么您使用的是哪种版本?非常感谢!您的建议非常有效-以下是AppController.php中的最后一段代码:public function beforeFilter(){//如果用户未登录$this->Auth->authror=\uuuu('您必须登录才能查看此页面');$this->Auth->flash['params']['class']='alert-alert-danger';}
$this->Auth->flash['params']['class'] = 'alert alert-danger';
<div id="authMessage" class="alert <?php echo $class; ?>"><?php echo $message; ?></div>
echo $this->Session->flash('authAlert', 'auth', array(class => 'alert-danger'));
echo $this->Session->flash('flash', array('params'=>array('class'=>'alert alert-danger')));