0

我在我的应用程序中使用 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

有谁知道为什么它不重定向到用户/登录页面?

先感谢您

4

1 回答 1

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
}
于 2013-03-12T16:17:58.670 回答