duannao1920 2015-05-27 14:11
浏览 57
已采纳

如何修改auth相关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?

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'
        ]
    ]);

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

I have debugged the Auth Component, there was a 'flash' setting, tried setting that, but it did not work?

So how do I change the authError to use a different Flash Layout?

Thanks,

  • 写回答

3条回答 默认 最新

  • doufu7835 2015-05-27 14:41
    关注

    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.

    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'
            ]
        ]
    ]);
    

    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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 孟德尔随机化结果不一致
  • ¥15 深度学习残差模块模型
  • ¥50 怎么判断同步时序逻辑电路和异步时序逻辑电路
  • ¥15 差动电流二次谐波的含量Matlab计算
  • ¥15 Can/caned 总线错误问题,错误显示控制器要发1,结果总线检测到0
  • ¥15 C#如何调用串口数据
  • ¥15 MATLAB与单片机串口通信
  • ¥15 L76k模块的GPS的使用
  • ¥15 请帮我看一看数电项目如何设计
  • ¥23 (标签-bug|关键词-密码错误加密)