简体   繁体   English

如何在CakePHP 2.0.4中为Auth组件使用不同的模型?

[英]How can I use different model for Auth component in CakePHP 2.0.4?

It looks like trivial thing, but I really can't find where I can change it. 看起来很琐碎,但我真的找不到可以更改的地方。 I want to use my "Player" model instead of User, but every time I go on /players/login it redirects me to "Missing Controller" page and link changes to /users/login. 我想使用“玩家”模型代替用户模型,但是每次我进入/ players / login时,它会将我重定向到“缺少控制器”页面,并将更改链接到/ users / login。

I tried: 我试过了:

public $components = array(
    'Session',
    'Auth' => array(
        'authenticate' => array('all' => array('userModel' => 'Player'))
     )
);

and

function beforeFilter() {
    $this->Auth->authenticate = array('all' => array('userModel' => 'Player'));
}

EDIT: SOLVED 编辑:已解决

'loginAction' => array('controller' => 'players', 'action' => 'login')

in $components array helped, I think :D 在$ components数组中,我认为:D

I guess the problem is that you aren't providing an authenticating system. 我想问题是您没有提供身份验证系统。 You're providing some settings to be used in all the authenticating system that will be chosen, but you haven't chosen one yet (you have to provide at least one like Form, Basic, Digest, ecc..). 您正在提供一些要在将要使用的所有身份验证系统中使用的设置,但是您尚未选择一个设置(您必须至少提供一种设置,例如Form,Basic,Digest等。)

$this->Auth->authenticate = array(
    'all' => array('userModel' => 'Member'),
    'Form',
    'Basic'
);

(or the same in the $components array) (或与$components数组相同)

You should do so 你应该这样做

public $components=array(
    'Session',
    'Auth'=>array(
        'authenticate'=>array(
            'Form'=>array(
                'userModel'=>'Player',
             )
        ),
        'loginAction'=>array('controller'=>'Players', 'action'=>'login'),

Use this code within controller : 在控制器中使用以下代码:

public $components = array(
    'Auth' => array(
    'loginRedirect' => array(
        'controller' => 'applications',
        'action' => 'index'
    ),

    'logoutRedirect' => array(
        'controller' => 'applications',
        'action' => 'login'
    ),

    'authenticate' => array(
            'Form' => array(
                'passwordHasher' => 'Blowfish',
                'userModel' => 'Application'
            )
        ),      
    )
);

Do not needed to add any code for beforeFilter() function. 不需要为beforeFilter()函数添加任何代码。 $components load the Auth conponent. $ components加载Auth组件。

Thanks Sujay 感谢Sujay

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM