在Cakephp 3中,使用另一个(不是用户,而是成员)控制器进行登录 [英] In Cakephp 3, Use another (not users but members) controller for login
问题描述
我正在使用Cakephp 3构建新的应用程序,用户必须在该应用程序中登录其帐户,但是我遇到了登录URL http://localserver.com/members/login ,它会将我重定向到 http://localserver.com /users/login
I am using Cakephp 3 for building new application where user have to login for their account however I am hitting the login URL http://localserver.com/members/login and it redirects me to http://localserver.com/users/login
貌似Auth组件中默认设置了用户"控制器.如何覆盖默认的控制器,从用户"到成员"?
Look like the 'users' controller is set by default in Auth component. How can I override the default controller from 'users' to 'members'?
注意:当我在本地服务器上工作时,这些URL不活跃.
NOTE: The URLs are not LIVE as I am working on my local-server.
推荐答案
是的,这与 userModel 配置键有关,默认为 Users .
Yes, this is related to the userModel config key, which defaults to Users.
在控制器的beforeFilter()或initialize()方法中尝试此脚本.
Try this script in your controller’s beforeFilter() or initialize() methods.
// Pass settings in
$this->Auth->config('authenticate', [
'Basic' => ['userModel' => 'Members'],
'Form' => ['userModel' => 'Members']
]);
更新:
除了要正常使用userModel
之外,还必须设置loginAction
.
Update:
In addition to userModel
to be worked properly you must set the loginAction
too.
// Pass settings in
$this->Auth->config('authenticate', [
'loginAction' => [
'controller' => 'Members',
'action' => 'login',
'plugin' => false, // or 'Members' if plugin
],
'Basic' => ['userModel' => 'Members'],
'Form' => ['userModel' => 'Members']
]);
这篇关于在Cakephp 3中,使用另一个(不是用户,而是成员)控制器进行登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!