问题
I'va been trying to change the 'userModel' from the default 'user' to 'usuario'. I'va done this before in CakePHP 1.3 but I can't get it to work using the lastest version.
Here's my code (AppController.php):
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Auth' => array(
'loginError' => "Nombre de usuario o contraseña incorrectos.",
'authError' => "Debes ingresar con tu cuenta de usuario.",
'loginRedirect' => array('controller' => 'administrador', 'action' => 'productos'),
'logoutRedirect' => array('controller' => 'usuarios', 'action' => 'login')
),
'Session',
'Email'
);
public function beforeFilter() {
$this->Auth->authenticate = array(
'Basic' => array('userModel' => 'Usuario'),
'Form' => array('userModel' => 'Usuario')
);
}
}
Thanks in advance.
EDIT: The component redirects me to "/users/login" instead of "/usuarios/login" and the login form in "/usuarios/login" doesn't work. It's like I never changed the userModel.
回答1:
Try doing this while initializing the Auth Component
In you AppController:
public $components = array(
'Auth' => array(
'authenticate' => array(
'Form' => array(
'userModel' => 'Usuario',
'fields' => array(
'username' => 'username',
'password' => 'password'
)
)
)
)
);
回答2:
Set custom UserModel
is nothing to do with Auth::loginAction
which is point to /users/login
by default. You can override it in Controller::beforeFilter()
callback or Controller::$components
array. Hope help.
回答3:
Change you $components
array to this:
public $components = array(
'Auth' => array(
'loginError' => "Nombre de usuario o contraseña incorrectos.",
'authError' => "Debes ingresar con tu cuenta de usuario.",
'loginRedirect' => array('controller' => 'administrador', 'action' => 'productos'),
'logoutRedirect' => array('controller' => 'usuarios', 'action' => 'login'),
'loginAction' => array('controller' => 'usuario','action' => 'login','plugin' => null),
'authenticate' => array('Form' => array('userModel' => 'Usuario')
),
),
'Session',
'Email'
);
回答4:
Try this code
App::uses('Controller', 'Controller');
class AppController extends Controller {
public $components = array(
'Auth' => array(
'loginError' => "Nombre de usuario o contraseña incorrectos.",
'authError' => "Debes ingresar con tu cuenta de usuario.",
'loginAction' => array('controller' => 'aucusers','action' => 'login'),
'loginRedirect' => array('controller' => 'administrador', 'action' => 'productos'),
'logoutRedirect' => array('controller' => 'usuarios', 'action' => 'login')
),
'Session',
'Email'
);
}
i hv added this the folowing line
'loginAction' => array('controller' => 'aucusers','action' => 'login'),
来源:https://stackoverflow.com/questions/17980196/cant-change-usermodel-using-authcomponent-in-cakephp