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

夙愿已清 提交于 2020-02-24 12:32:08

问题


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.

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


回答1:


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

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

(or the same in the $components array)




回答2:


You should do so

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



回答3:


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. $components load the Auth conponent.

Thanks Sujay



来源:https://stackoverflow.com/questions/8996162/how-can-i-use-different-model-for-auth-component-in-cakephp-2-0-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!