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条)

报告相同问题?

悬赏问题

  • ¥30 c#打开word开启修订并实时显示批注
  • ¥15 如何解决ldsc的这条报错/index error
  • ¥15 VS2022+WDK驱动开发环境
  • ¥30 关于#java#的问题,请各位专家解答!
  • ¥30 vue+element根据数据循环生成多个table,如何实现最后一列 平均分合并
  • ¥20 pcf8563时钟芯片不启振
  • ¥20 pip2.40更新pip2.43时报错
  • ¥15 换yum源但仍然用不了httpd
  • ¥50 C# 使用DEVMOD设置打印机首选项
  • ¥15 麒麟V10 arm安装gdal