2011-11-01 72 views
1

我在CakePHP 1.3中使用了ACL,沒有發生任何問題,經過兩週苦澀的挫折後,它仍然無法在CakePHP 2.0中工作。CakePHP 2.0:ACL不工作

我完全遵循Cake ACL教程,但沒有任何反應。所有Aros都正確,ACOS和權限相同。

畢竟,我可以毫無問題地輸入所有被拒絕的操作。

特此我的AppController:

public $components = array('Acl','Auth'=> array(
          'authenticate' => array(
           'Actions', 
           'Form' => array(
            'fields' => array('username' => 'email') 
            ), 
          ) 
), 'Session', 'MathCaptcha', 'RequestHandler'); 

在我BeforeFilter:

$this->Auth->actionPath = 'controllers'; 
    $this->Auth->loginAction = array('controller' => 'users', 'action' => 'login'); 
    $this->Auth->logoutRedirect = array('controller' => 'pages', 'action' => 'home'); 
    $this->Auth->loginRedirect = array('controller' => 'users', 'action' => 'profile'); 
    $this->Auth->allow('display'); 

是否有人有一個想法是什麼出了問題。謝謝!

回答

2

在CakePHP 2.0我做了這種方式:

應用程序/控制器/ AppController.php

class AppController extends Controller { 

    public $components = array(
     // others components... 
     'Session', 
     'Acl', 
     'Auth'=> array(
      // Setting AUTHORIZATION "What can you do?" 
      'authorize' => array(
       'Actions' => array(
        'actionPath' => 'controllers' 
       ) 
      ), 

      // Setting AUTHENTICATION "Who are you?" 
      'authenticate' => array(
       'Form' => array(
        'fields' => array(
         'username' => 'email', 'password' => 'password' 
        ) 
       ) 
      ) 
     ) 
    ); 

// other stuffs... 

通過這種形式給出,ACL將盡一切骯髒的工作。正如你可能知道的那樣,不需要檢查permition。

我相信你對ARO和ACO確實沒什麼大不了的。以防萬一: http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/simple-acl-controlled-application.html#simple-acl-controlled-application

CakeBook for 2.0顯示一個名爲AclExtras的Console插件,用於構建您的ACO。您的ARO將隨着用戶和組的添加/刪除而建立。我已經使用這個插件來生成關於我已經填充的表格的ARO:http://www.alaxos.ch/blaxos/pages/view/plugin_acl。這工作fos 1.3,但有2.0的測試版,工作正常。

之後,您必須設置permition。手動(或從控制檯),因爲此鏈接描述:http://book.cakephp.org/2.0/en/tutorials-and-examples/simple-acl-controlled-application/part-two.html#setting-up-permissions。或者用Alaxos的Plugin進行視覺。

我希望這個幫助!這對我很有用。我正在使用CakePHP 2.0.2

+0

非常感謝答案Colares,連同斯科特的答案,我設法讓它工作。 – ChrisDK

2

Auth組件從CakePHP 1.3改爲2.0很多。我碰到類似的問題,將應用程序從1.3遷移到2.0。我發現,設置在authorize選擇是,我需要讓我的變化:

在beforeFilter:

$this->Auth->authorize = array(
    'Actions' => array(
     'userModel' => 'User', 
     'actionPath' => 'users' 
    ) 
); 

中的usermodel是在阿羅表使用的模型類。 actionPath是Acl在Aco表中檢查的操作的根級別。

你也可以拒絕然後讓:

$this->Auth->deny('*'); 
$this->Auth->allow('display'); 

希望這有助於。

+0

太棒了,非常感謝! – ChrisDK