2017-05-09 87 views

回答

1

使用安全组件通常是在控制器beforeFilter()中完成的。您将指定您想要的安全限制,安全组件将在其启动时强制执行它们:

class AppController extends Controller { 
    // Add security component 
    public $components = array('Security'); 

    public function beforeFilter() { 
     $this->Security->blackHoleCallback = 'forceSSL'; 
     $this->Security->requireSecure(); 
    } 

    // Add this function in your AppController 
    public function forceSSL() { 
     return $this->redirect('https://' . env('SERVER_NAME') . $this->here); 
    } 
}