Question

I'm implementing the CakePHP ACL. I want my Model to both be a requester and controlled, so I've set it up like this:

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

The problem I'm having, is that my Model has a different parent depending on the type of node (ACO or ARO) it is.

I would like to solve it by doing something like this with the parentNode() function:

public function parentNode() {

    if('ARO' == $this->type) {
        return 'ARO parent';
    } else {
        return 'ACO parent';
    }

}

So basically let it return the appropriate parent for each of the cases.

Is this possible, and if so, how?

===== UPDATE - 2013-10-04 =====

I've submitted an official ticket which is being looked at :-)

https://cakephp.lighthouseapp.com/projects/42648/tickets/4122-add-type-as-argument-to-the-parentnode-function#ticket-4122-2

Était-ce utile?

La solution

I've been doing some digging in the Cake logic. I think I came up with a very simple and useful solution for this issue.

Using CakePHP 2.4.1, I've edited the file /lib/Cake/Model/Behavior/AclBehavior.php

On line 109 it reads:

$parent = $model->parentNode();

I've simply added the type as argument:

$parent = $model->parentNode($type);

That way, my parentNode() function can look like this:

public function parentNode($sType) {

    if('ARO' == $sType) {
        return 'ARO parent';
    } else {
        return 'ACO parent';
    }

}

Me happy :-)

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top