1
votes

I've done a simple "change_email" function with its view and all the stuff in the controller. Everything is actually working fine except saving the data. When I submit my form and my model actually runs its save()-Method CakePHP throws an error:

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

Of course he doesn't find the node, since it hasn't been created (when a user registers his account, a node won't be created automatically). I'm curious about why my model wants to find the node since its not needed for the actual operation.

public function change_email()
    {
        if ($this->request->is("put")) {
            if (!empty($this->request->data)) {
                $this->User->validator()
                    ->add('password', array(
                        'valid' => array(
                            'rule' => 'validatePassword'
                        )
                    ))
                    ->add('email_confirm', array(
                        'valid' => array(
                            'rule' => 'validateEmail'
                        )
                    ));
                if ($this->User->save($this->request->data)) {
                    $this->set("status", true);
                }
            }
        }
    }

Thats my code in the controller. The model has no real effect except its beforeFilter() method which only hashes the password.

Does anyone have an idea?

1

1 Answers

1
votes

Using Acl usually requires parnetNode() and bindNode() methods within your User and Group model if it applies.

Using AclBehavior

Most of the AclBehavior works transparently on your Model’s afterSave(). However, using it requires that your Model has a parentNode() method defined. This is used by the AclBehavior to determine parent->child relationships. A model’s parentNode() method must return null or return a parent Model reference.

Within User model belonging to a Group model

public function parentNode() {
    if (!$this->id && empty($this->data)) {
        return null;
    }
    $data = $this->data;
    if (empty($this->data)) {
        $data = $this->read();
    }
    if (!$data['User']['group_id']) {
        return null;
    } else {
        return array('Group' => array('id' => $data['User']['group_id']));
    }
}

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

Within Group model, or if the User model doesn't have any parent associations, it should return null

public $actsAs = array('Acl' => array('type' => 'requester'));

public function parentNode() {
    return null;
}

You will also want to make sure you are updating your acos table with new methods and controllers. AclExtras is a nice plugin that can automate this for you.