2013-04-02 37 views
0

我試圖在我的本地開發環境中禁用ACL/ACO檢查,因爲每次創建新方法或控制器時都需要耗費時間來同步ACO表。我有問題想出如何有條件地做到這一點。我試圖在AppController中下面的代碼,但它不工作:在本地開發環境中禁用CakePHP ACL/ACO檢查

public function beforeFilter() { 
    parent::beforeFilter(); 

    // disable ACL component in local development environments 
    if(preg_match('/\.local/',FULL_BASE_URL)){ 
     unset($this->components['Acl']); 
     unset($this->components['Auth']['authorize']); 
    } 
} 

我正在CakePHP的2.x的

回答

4

你大概可以達到同樣的是這樣的:

在您的應用程序添加配置/Config/core.php

Configure::write('Auth.enabled', 0); 

與自動檢測您的環境相比,顯式配置通常是首選。

然後,在你的AppController中;

public function beforeFilter() 
{ 
    if(0 === Configure::read('Auth.enabled')) { 
     $this->Auth->allow(); 
    } 
} 

Making actions public

或者,要完全禁用成分(S):

public function beforeFilter() 
{ 
    if(0 === Configure::read('Auth.enabled')) { 
     $this->Components->disable('Acl'); 
     $this->Components->disable('Auth'); 
    } 
} 
+0

+1'$這個 - > Auth->允許();' – nIcO

+0

謝謝,我不知道Components :: disable方法。 – systematical

+0

很高興能幫到你! – thaJeztah