2017-05-09 91 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); 
    } 
}