【问题标题】:CakePHP - Controller::redirect and Auth->logoutRedirect not workingCakePHP - Controller::redirect 和 Auth->logoutRedirect 不起作用
【发布时间】:2015-04-17 04:41:25
【问题描述】:

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

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

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

非常感谢!

【问题讨论】:

    标签: php cakephp redirect


    【解决方案1】:

    这是注销后重定向的模式:

    // 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-12
      相关资源
      最近更新 更多