如何修改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,

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

I think I have got a solution.

It seems that when I print $this->Flash->render('auth');

I need to change it at this point to $this->Flash->render('auth',['element' => 'error']);

But if anyone knows any better ways to do this, please let me know

In Cakephp 3 you can define element name for flash errors -

$this->loadComponent('Auth', array(
    'authorize'=> 'Controller',
    'flash' => array(
        'element' => 'error'
    ),
    'authError' => 'Your session expired, please login again',
    'logoutRedirect' => array(
        'controller' => 'Users',
        'action' => 'login',
        'prefix' => false
     )
));

and error.ctp at - \src\Template\Element\Flash\error.ctp