我在我的应用程序中使用ACL。我已经在我的AppController中的beforeFilter中定义了我的loginAction,但仍然没有重定向到正确的位置。我想做的是当用户像这样访问应用程序时 - localhost / intraweb必须重定向到localhost / intraweb / users / login
这是我的AppController代码
class AppController extends Controller {
public $helpers = array('Html', 'Form', 'CustomFields.Field');
public $components = array(
'CustomFields.Field',
'Acl',
'Auth' => array(
'authorize' => array(
'Actions' => array('actionPath' => 'controllers')
)
),
'Session',
'Cookie',
);
public $uses = array('User');
public function beforeFilter() {
//Configure AuthComponent
$this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
$this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'login');
$this->Auth->allow('display');
//OTHER CODE
}
这是我的PagesController代码
class PagesController extends AppController {
public function beforeFilter() {
parent::beforeFilter();
$this->Auth->allow();
}
//Other code
有没有人知道为什么它不会重定向到用户/登录页面?
提前谢谢
答案 0 :(得分:0)
loginRedirect表示未找到Auth Session时要调用的操作。简单来说就是登录页面。在没有需要身份验证的情况下允许通过的操作永远不会重定向到loginRedirect。
当您访问localhost/intraweb
时,Cake会呈现Pages/display
,因为您的代码中有$this->Auth->allow('display');
。 Auth将让它呈现而无需重定向到loginRedirect。
<强>更新强>
在其他控制器中重新声明beforeFilter()会覆盖AppController中的所有声明。因此,如果要继承AppController中的beforeFilter()声明,
public function beforeFilter() {
parent::beforeFilter(); // inherit beforeFilter() from AppController
// your controller specific declarations
}