如何修改auth相关flash消息的外观? [英] How to modify the appearance of auth related flash messages?
问题描述
我没有运气试图将AuthError上的Flash元素从默认更改为错误?
I am having no luck trying to change the Flash Element on the AuthError from default to error?
我只是想看看是否可以改变它,但是现在它驱动我在墙上,我似乎不能改变它?
I was just trying to see if I can change it, but now its driving me up the wall as I can not seem to change it?
这是我在AppController中加载我的Auth的方法,
This is how I have loaded my Auth in the AppController,
$this->loadComponent('Auth', [
'authError' => 'Did you really think you are allowed to see that? -2',
'authenticate' => [
'Form' => [
'fields' => ['username' => 'email', 'password' => 'password']
]
],
'loginAction' => [
'controller' => 'Users',
'action' => 'Login'
],
'loginRedirect' => [
'controller' => 'Pages',
'action' => 'LoginPage'
],
'logoutRedirect' => [
'controller' => 'Pages',
'action' => 'HomePage'
]
]);
所以当我去一个不允许的页面,它显示authError消息,但使用任何类/是在 Element / Flash / default.ctp
我想改变它只是使用相同的 error.cpt
So when I go to a not allowed page, it displays the authError message but using whatever class/id's are in the Element/Flash/default.ctp
I wanted to change it to just use the same as the error.cpt
我已经调试了Auth组件,有一个'flash'设置,尝试设置,但它不工作?
I have debugged the Auth Component, there was a 'flash' setting, tried setting that, but it did not work?
那么如何更改authError以使用不同的Flash布局?
So how do I change the authError to use a different Flash Layout?
感谢,
推荐答案
默认使用 default.ctp
元素,并且可以在直接渲染时配置flash元素。
As you've figured, auth messages are using the default.ctp
element by default, and that it's possible to configure the flash element when rendering it directly. To affect this globally, you can configure the component instead.
如果你想做的只是更改类名,那么你可以使用
flash
中的参数
params
设置:
If all you want to do is to change the classname, then you can use the class
parameter in the flash
configuration options params
setting:
$this->loadComponent('Auth', [
// ...
'flash' => [
'params' => [
'class' => 'some-custom-class'
]
]
]);
如果要使用不同的元素,例如 error.ctp
一个,只需使用元素
设置指定其名称
If you want to use a different element, for example the error.ctp
one, just use the element
setting to specify its name
'flash' => [
'element' => 'error'
]
See also Cookbook > Controllers > Components > Authentication > Configuration Options
这篇关于如何修改auth相关flash消息的外观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!