使用initialize的cakedp3中的httpd https重定向不会工作

时间:2017-11-20 01:21:49

标签: cakephp cakephp-3.0

对于我的所有控制器,我无法获得以下代码(下面的搜索功能代码无法使用Appcontroller中的代码)。问题是我有一些搜索功能,用参数再次调用该函数。使用以下代码进行初始化意味着我使用的搜索功能不再有效。有没有办法在appcontroller中为httpds重定向放置相同的代码,而不是在initialize函数中?

//search controller which no longer works with htttps request from ap controller

     if (($this->request->is('post') || $this->request->is('put'))) {
            //  debug( $this->request->data);
            if (isset($this->request->data['searchFilter'])) {
                $filter_url['controller'] = $this->request->params['controller'];
                $filter_url['action'] = $this->request->params['action'];
                $filter_url['page'] = 1;

                // for each filter we will add a GET parameter for the generated url
                foreach($this->request->data as $name => $value){
                    if($value){
                        $filter_url[$name] = urlencode($value);
                    }
                }
                //Post params are now GET paramaters
                return $this->redirect($filter_url); //this no longer works with the appcontroller redirect

            }//isset   filter

        }//post

............

 //app controller
 public function initialize()
    {
        parent::initialize();
        $this->loadComponent('Security', ['blackHoleCallback' => 'forceSSL']);
    }

    public function beforeFilter(Event $event)
    {

            $this->Security->requireSecure();

    }

    public function forceSSL()
    {
        return $this->redirect('https://' . env('SERVER_NAME') . $this->request->getRequestTarget());
    }

https://book.cakephp.org/3.0/en/controllers/components/security.html#usage

0 个答案:

没有答案