身份验证组件问题
我试图让我的管理路由与身份验证组件一起使用。我希望以下路由能够工作。
Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));
但是当我输入 /admin 时,它会重定向到 /admin/users/login 并显示此错误。
Create UsersController::admin_login() in file: cms.local/controllers/users_controller.php
这是我的 app_controller 代码。
class AppController extends Controller {
var $components = array('DebugKit.Toolbar','Auth','Session');
function beforeFilter(){
//Set up Auth Component
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'admin_index');
$this->Auth->allow('display');
}
}
users_controller
<?php
class UsersController extends AppController {
var $name = 'Users';
function login(){
}
function admin_logout(){
$this->Session->destroy();
$this->redirect($this->Auth->logout());
}
}
?>
如果您需要更多信息,请告诉我。
谢谢
Im trying to get my admin routing working with the auth component. I want the following routing to work.
Router::connect('/admin', array('controller' => 'pages', 'action' => 'index', 'admin' => true));
but when i type in /admin it redirects to /admin/users/login and display this error.
Create UsersController::admin_login() in file: cms.local/controllers/users_controller.php
here is my app_controller code.
class AppController extends Controller {
var $components = array('DebugKit.Toolbar','Auth','Session');
function beforeFilter(){
//Set up Auth Component
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'admin_index');
$this->Auth->allow('display');
}
}
users_controller
<?php
class UsersController extends AppController {
var $name = 'Users';
function login(){
}
function admin_logout(){
$this->Session->destroy();
$this->redirect($this->Auth->logout());
}
}
?>
If you require more information let me know.
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
别担心,一切正常:)
在 AppController::beforeFilter() 中,您声明为了登录,
当您使用 admin 转到 Pages/index 时 ,loginAction 是 Users/login (Users/admin_login 如果 admin=>true) =>true 并且您尚未登录,您将被重定向到 Users/admin_login,如下所示:
未找到 UsersController::admin_login() 方法,您应该创建它。
Dont worry, all works ok :)
In AppController::beforeFilter() you stated that in order to log in, the loginAction is Users/login (Users/admin_login if admin=>true)
when you go to Pages/index with admin=>true and you are not logged in, you are being redirected to Users/admin_login, and as this tells:
The method UsersController::admin_login() is not found and you should create it.
这对我来说很好:-
This worked for me fine:-
您可以通过指定
'admin' => 强制 Auth 使用无前缀登录操作。 false
在你的loginAction中。这样,所有需要身份验证的操作都将使用无前缀登录操作。所以你的 beforeFilter 看起来像这样:同样,你可以采取另一种方式并指定 'admin' => true 表示仅使用 admin_login。
You can force Auth to use the non-prefixed login action by specifying
'admin' => false
in your loginAction. This way, all actions that require authentication will use the non-prefixed login action. So your beforeFilter would look something like this:Similarly, you could go the other way and specify 'admin' => true to only use admin_login.