问题描述
我一直在尝试将 userModel从默认的 user更改为 usuario。我以前在CakePHP 1.3中已经做到了,但是我无法使用最新版本来工作。
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.
这是我的代码(AppController.php):
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')
);
}
}
谢谢。
编辑:该组件将我重定向到 / users / login,而不是 / usuarios / login,并且 / usuarios / login中的登录表单不起作用。就像我从未更改过userModel。
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.
推荐答案
设置自定义 UserModel
是与 Auth :: loginAction
无关,默认情况下它指向 / users / login
。您可以在 Controller :: beforeFilter()
回调或 Controller :: $ components
数组中覆盖它。希望有帮助。
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.
这篇关于无法在CakePHP中使用AuthComponent更改“ userModel”的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!