问题
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