各种$这个 - >验证在CakePHP中 [英] Various $this->Auth in cakephp

查看:188
本文介绍了各种$这个 - >验证在CakePHP中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我配置验证组件来管理页面,利用用户模型。但现在,我也想创建/配置一个验证客户端。我试图改写的inialize()

I configure a Auth component to "Admin page", using the users model. But now, I also want create/configure a Auth to the clients. I try "rewrite" the inialize()

//This is in my ClientsController.php
public function initialize()
{
    $this->loadComponent('RequestHandler');
    $this->loadComponent('Flash');
    $this->loadComponent('Auth', [
        'authenticate' => [
            'Form' => [
                'userModel' => 'clients',
                'fields' => ['username' => 'client_email', 'password' => 'client_password']
            ]
        ],
        'loginRedirect' => [
            'controller' => 'Clients',
            'action' => 'index'
        ],
        'logoutRedirect' => [
            'controller' => 'Clients',
            'action' => 'login'
        ],
    ]);
}

有了这个,我收到此记录(如果使用父:: initalize()收到相同)

With this, I receive this log(if uses parent::initalize() receive the same)

[RuntimeException] The "Auth" alias has already been loaded with the following config: array (...

我不希望建立一个验证manualy。如何更多地使用的验证?

I not want create a "Auth" manualy. How to use more of one Auth?

感谢....

推荐答案

您不要使用多重身份验证组件实例,但重新配置简单,它在扩展控制器,采用了组件配置()方法,沿着东西线

You don't use multiple auth component instances, but simple reconfigure it in the extended controller, using the components config() method, something along the lines of

public function initialize()
{
    parent::initialize();

    // ...

    $this->Auth->config([
        'authenticate' => [
            'Form' => [
                'userModel' => 'clients',
                'fields' => [
                    'username' => 'client_email',
                    'password' => 'client_password'
                ]
            ]
        ],
        'loginRedirect' => [
            'controller' => 'Clients',
            'action' => 'index'
        ],
        'logoutRedirect' => [
            'controller' => 'Clients',
            'action' => 'login'
        ],
    ]);
}

另请参阅 <一个href=\"http://book.cakephp.org/3.0/en/controllers/components/authentication.html#configuration-options\"相对=nofollow>食谱>控制器>组件>认证>配置选项

See also Cookbook > Controllers > Components > Authentication > Configuration options

这篇关于各种$这个 - &GT;验证在CakePHP中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆