CakePHP - Controller::redirect 和 Auth->logoutRedirect 不工作

CakePHP - Controller::redirect and Auth->logoutRedirect not working

我的 CakePHP 2.5.3 应用程序位于子域 (domain/project_name) 中,并且 apache 重写规则工作正常。

在 app/Config/core.php 中设置 App.fullBaseUrl='domain/project_name' 后,Router::fullBaseUrl() 工作正常但是,所有 $this->Controller ->redirect 和所有 AuthComponent 重定向到 http://domain/project_name/project_name/controller/action.

有没有其他人遇到过这个问题,你是如何解决的?

非常感谢!

这是退出后重定向的模式:

// app/Controller/AppController.php
class AppController extends Controller {
    //...

    public $components = array(
        'Session',
        'Auth' => array(
            'loginRedirect' => array(
                'controller' => 'posts',
                'action' => 'index'
            ),
            'logoutRedirect' => array(      // <-- Let's focus at here.
                'controller' => 'pages',
                'action' => 'display',
                'home'
            ),
            'authenticate' => array(
                'Form' => array(
                    'passwordHasher' => 'Blowfish'
                )
            )
        )
    );

    public function beforeFilter() {
        $this->Auth->allow('index', 'view');
    }
    //...
}

来源:http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout

在您的问题上下文中,检查 logoutRedirect 配置数组。


如果您想通过其他方式处理重定向:

public function logout() {
    return $this->redirect($this->Auth->logout());
}

来源:http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html#authentication-login-and-logout