CakePHP 1.3:登录时重定向

时间:2012-02-15 19:36:01

标签: cakephp cakephp-1.3

我在我的应用程序中使用ACL和Auth。

如果已注销的用户将内部书签页面加载到站点(主页除外),则Cake会正确提示登录。但是,登录后,它会重定向到用户在登录前尝试访问的URL。

我需要让用户在登录后重定向到pages / home,无论他们尝试访问哪个网址。

到目前为止,我还没有找到$ this-> Auth命令来完成此任务。有什么想法吗?

以下是app_controller.php的验证码

    function beforeFilter() {
    //Configure AuthComponent
    //$this->Auth->allow(array('*'));
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login');
    $this->Auth->logoutRedirect = array('controller' => 'users', 'action' => 'login');
    $this->Auth->loginRedirect = array('controller' => 'pages', 'action' => 'home');
    $this->Auth->actionPath = 'controllers/';

感谢您的任何想法

1 个答案:

答案 0 :(得分:1)

确保在beforeFilter函数中包含以下内容:

function beforeFilter() {
    $this->Auth->autoRedirect = false;
    parent::beforeFilter();
}

另外请确保登录功能中没有这样的内容:

$this->redirect($this->Auth->redirect());

Auth-> redirect()返回用户在进入登录页面或Auth-> loginRedirect之前登陆的网址。

您应该能够在登录功能中使用$this->redirect或通过设置默认的登录重定向重定向到您想要的任何位置。