3
votes

as the title already says I've got a problem with the Acl Tutorial of CakePHP 2. I've done everything exactly the way it is mentioned in the Tutorial, but still it doesn't work.

I know that there are many people on the internet which have also a problem with this tutorial, but I can't find any blog entry or whatever with the same problem like me. When I try to access a direction of my app I get the following error:

Notice (8): Undefined index: group_id [APP\Model\User.php, line 98]

and:

AclNode::node() - Couldn't find Aro node identified by "Array ( [Aro0.model] => Group [Aro0.foreign_key] => ) "

So there isn't any value for the foreign_key transmitted to the Acl at all. But the strange thing is that -at least in the functions of the userscontroller- the foreign_key is set properly but when it should be passed to the Acl it is gone

Nr  Query   Error   Affected    Num. rows   Took (ms)

1   SELECT COUNT(*) AS `count` FROM `cake`.`users` AS `User` WHERE `User`.`id` = 4
2   SELECT COUNT(*) AS `count` FROM `cake`.`users` AS `User` WHERE `User`.`id` = 4
3   SELECT COUNT(*) AS `count` FROM `cake`.`users` AS `User` WHERE `User`.`id` = 4
4   UPDATE `cake`.`users` SET `modified` = '2012-11-13 19:59:47' WHERE `cake`.`users`.`id` = '4'
5   SELECT `User`.`group_id` FROM `cake`.`users` AS `User` WHERE `User`.`id` = 4 LIMIT 1
6   SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `cake`.`aros` AS `Aro` LEFT JOIN `cake`.`aros` AS `Aro0` ON (`Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght`) WHERE `Aro0`.`model` = 'Group' AND `Aro0`.`foreign_key` = 2 ORDER BY `Aro`.`lft` DESC
7   SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `cake`.`aros` AS `Aro` LEFT JOIN `cake`.`aros` AS `Aro0` ON (`Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght`) WHERE `Aro0`.`model` = 'User' AND `Aro0`.`foreign_key` = 4 ORDER BY `Aro`.`lft` DESC
8   SELECT COUNT(*) AS `count` FROM `cake`.`aros` AS `Aro` WHERE `Aro`.`id` = 6
9   SELECT COUNT(*) AS `count` FROM `cake`.`aros` AS `Aro` WHERE `Aro`.`id` = 6
10  SELECT `Aro`.`parent_id` FROM `cake`.`aros` AS `Aro` WHERE `Aro`.`id` = 6 LIMIT 1
11  SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`lft`, `Aro`.`rght` FROM `cake`.`aros` AS `Aro` WHERE 1 = 1 AND `Aro`.`id` = 6 LIMIT 1
12  SELECT `Aro`.`id`, `Aro`.`lft`, `Aro`.`rght` FROM `cake`.`aros` AS `Aro` WHERE 1 = 1 AND `Aro`.`id` = 2 LIMIT 1
13  SELECT COUNT(*) AS `count` FROM `cake`.`aros` AS `Aro` WHERE `Aro`.`id` = 6
14  UPDATE `cake`.`aros` SET `parent_id` = 2, `model` = 'User', `foreign_key` = 4, `id` = 6 WHERE `cake`.`aros`.`id` = '6'
15  SELECT `Aro`.`id`, `Aro`.`parent_id`, `Aro`.`model`, `Aro`.`foreign_key`, `Aro`.`alias` FROM `cake`.`aros` AS `Aro` LEFT JOIN `cake`.`aros` AS `Aro0` ON (`Aro`.`lft` <= `Aro0`.`lft` AND `Aro`.`rght` >= `Aro0`.`rght`) WHERE `Aro0`.`model` = 'Group' AND `Aro0`.`foreign_key` IS NULL ORDER BY `Aro`.`lft` DESC

The lines from the error message are:

public function bindNode($user) {
    return array('model'=>'Group','foreign_key'=>$user['User']['group_id']);
}

So why is the value of the foreign_key firstly '2' (how it is supposed to be) and afterwards NULL ?

I hope some of you are able to help me. Thanks.

PS: For everyone who would prefer the german version of my question, here it is

UPDATE: I was able to make it work for all functions of the userscontroller through this:

public function bindNode() {
    $this->id;
    $data = $this->read();
    return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);
    }

But for all other Controllers its still the same.. Has any one an idea how i could get the users data in the model, so that it works also for the other controllers?

1

1 Answers

4
votes

I know its a bit stupid to answer my own question, but instead of deleting the question i think it would be better to leave it here for anybody who has the same problem, because there seems to be no answer for this on the internet.

I was able to solve the problem through the following code:

public function bindNode() {
    $data = AuthComponent::user();
    return array('model' => 'Group', 'foreign_key' => $data['User']['group_id']);
    }

It seems to work perfectly, and maybe it could help some others ;)