开发者

Doing the CakePHP Acl tutorial. I can't seem to populate aros_acos

I could've sworn I've done the tutorial correctly, but I am getting an error message and my aros_acos table is empty.

What I've already done:

  1. On this page: http://book.cakephp.org/view/646/Creating-ACOs I've run "cake acl create aco root controllers" and it returned "New Aco 'controllers' created.". I've also added "$this->Auth->actionPath = 'controllers/';" to the beforeFilter() of AppsController. I do not understand the other piece of code since it is badly explained where it should go -- what exactly does it mean by "using the AclComponent"?

  2. I've run the build_acl() from this page: http://book.cakephp.org/view/647/An-Automated-tool-for-creating-ACOs It has populated my 'acos' table with 46 entries.

  3. This is the page where I believe the issues lies: http://book.cakephp.org/view/648/Setting-up-permissions I copied the code found on the page into my apps_controller.php and ammended it slightly to point to the ids of the groups I'm using:

    function initDB() { $group =& $this->User->Group;

    //Allow admins to everything
    $group->id = 5;
    $this->Acl->allow($group, 'controllers');
    
    //allow managers to posts and widgets
    $group->id = 6;
    $this->Acl->deny($group, 'controllers');
    $this->Acl->allow($group, 'controllers/Posts');
    $this->Acl->allow($group, 'controllers/Widgets');
    
    //allow users to only add and edit on posts and widgets
    $group->id = 7;
    $this->Acl->deny($group, 'controllers');
    $this->Acl->allow($group, 'controllers/Posts/add');
    $this->Acl->allow($group, 'controllers/Posts/edit');
    $this->Acl->allow($group, 'controllers/Widgets/add');
    $this->Acl->allow($group, 'controllers/Widgets/edit');
    

    }

I've also taken all references to allowedActions from my users and groups controllers, and added the correct code to my posts, widget开发者_运维技巧s and AppController pages...

When running the initDB() inside AppController by visiting http://localhost/basic_cake2/groups/initDB I get a warning message on the top of my screen. It says:

DbAcl::allow() - Invalid node [CORE/cake/libs/controller/components/acl.php, line 325]

CONTEXT:

$aro = stdClass stdClass::$id = 5 $aco = "controllers" $actions = "*" $value = 1 $perms = false $permKeys = array( "_create", "_read", "_update", "_delete" ) $save = array()

CODE:

    if ($perms == false) {
        trigger_error(__('DbAcl::allow() -

Invalid node', true), E_USER_WARNING);

AND ALSO SHOWS:

DbAcl::allow() - CORE/cake/libs/controller/components/acl.php, line 325 AclComponent::allow() - CORE/cake/libs/controller/components/acl.php, line 101 AppController::initDB() - APP/app_controller.php, line 23 Object::dispatchMethod() - CORE/cake/libs/object.php, line 116 Dispatcher::_invoke() - CORE/cake/dispatcher.php, line 227 Dispatcher::dispatch() - CORE/cake/dispatcher.php, line 194 [main] - APP/webroot/index.php, line 88

On checking the aros_acos table I find that nothing has been added!

Therefore the authentication doesn't work on any pages... :( Does anybody have any ideas? I've no idea how to debug this and I asked on #cakephp but they were quite silent in response and basically just told me to re-read the documentation.

EDIT: Okay, so I read the tutorial a little harder and it turns out I've been running the function from the wrong file. I moved it to the Users Controller and it added 3 rows to the aros_acos table.

However, I'm still getting that error message so I think something is still going wrong!

The context for the error message does seem to have changed, which is interesting. It now reads:

$aro = Group

Group::$name = "Group"

Group::$validate = array

Group::$hasMany = array

Group::$actsAs = array

Group::$useDbConfig = "default"

Group::$useTable = "groups"

Group::$displayField = "name"

Group::$id = 6

Group::$data = array

Group::$table = "groups"

Group::$primaryKey = "id"

Group::$_schema = array

Group::$validationErrors = array

Group::$tablePrefix = ""

Group::$alias = "Group"

Group::$tableToModel = array

Group::$logTransactions = false

Group::$transactional = false

Group::$cacheQueries = false

Group::$belongsTo = array

Group::$hasOne = array

Group::$hasAndBelongsToMany = array

Group::$Behaviors = BehaviorCollection object

Group::$whitelist = array

Group::$cacheSources = true

Group::$findQueryType = NULL

Group::$recursive = 1

Group::$order = NULL

Group::$__exists = NULL

Group::$__associationKeys = array

Group::$__associations = array

Group::$__backAssociation = array

Group::$__insertID = NULL

Group::$__numRows = NULL

Group::$__affectedRows = NULL

Group::$_findMethods = array

Group::$_log = NULL

Group::$User = User object

Group::$Aro = Aro object

$aco = "controllers/Posts"

$actions = "*"

$value = 1

$perms = false

$permKeys = array(

"_create",

"_read",

"_update",

"_delete"

)

$save = array()


I fixed it. For future reference:

  1. I deleted the contents of all of the tables in order to start from scratch.
  2. I'd been running the initDB() from the wrong file. I correctly moved it to the Users Controller. Running it no longer gave an error message and added the correct entries to aros_acos.

Fixed!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜