我已为管理员面板完成了管理路由。现在,网址是 localhost / app / admin 。
现在我有2个表管理员和用户。
我为登录 localhost / app / admin / admins / login 创建了一个网址。
页面提示输入用户名和密码。
但问题是在使用loginredirect的appcontroller中创建组件时,它被重定向到 localhost / app / admin / users / login 。我不知道为什么。我甚至尝试更改loginredirect路径,但它没有任何效果。
这是我的appcontroller.php:
public $components = array(
'Session',
'Auth' => array(
'loginRedirect' => array('controller' => 'admins', 'action' => 'add'),
'logoutRedirect' => array('controller' => 'pages', 'action' => 'display', 'home')
)
);
public function beforeFilter() {
$this->Auth->allow('index', 'view');
}
即使我删除了用户表,它也会重定向到用户登录。
答案 0 :(得分:0)
听起来你的Auth组件无效。而不是将auth重定向添加到components变量中,而是将它们放在beforeFilter()中。你的appController应该是:
public $components = array('Auth','Session');
public function beforeFilter()
{
$this->Auth->loginRedirect = array('action' => 'add', 'controller' => 'admins');
$this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'display', 'home');
$this->Auth->authError = 'You are not allowed to see that.';
}
您是否已成功登录?如果是这样,请检查routes.php以确保正确路由。这可以通过尝试手动导航到example.com/admins/add来测试。