diff --git a/src/Model/Behavior/AclBehavior.php b/src/Model/Behavior/AclBehavior.php index 7e49e866..dd2f4938 100644 --- a/src/Model/Behavior/AclBehavior.php +++ b/src/Model/Behavior/AclBehavior.php @@ -72,15 +72,16 @@ public function __construct(Table $model, array $config = []) } foreach ($types as $type) { $alias = Inflector::pluralize($type); - $className = App::className($alias . 'Table', 'Model/Table'); + $className = App::className($alias, 'Model/Table', 'Table'); if ($className == false) { - $className = App::className('Acl.' . $alias . 'Table', 'Model/Table'); + $className = App::className('Acl.' . $alias, 'Model/Table', 'Table'); } $config = []; if (!TableRegistry::getTableLocator()->exists($alias)) { $config = ['className' => $className]; } - $model->hasMany($type, [ + + $model->hasMany($alias, [ 'targetTable' => TableRegistry::getTableLocator()->get($alias, $config), ]); } @@ -94,7 +95,7 @@ public function __construct(Table $model, array $config = []) * Retrieves the Aro/Aco node for this model * * @param string|array|Model $ref Array with 'model' and 'foreign_key', model object, or string value - * @param string $type Only needed when Acl is set up as 'both', specify 'Aro' or 'Aco' to get the correct node + * @param string $type Pluralized! Only needed when Acl is set up as 'both', specify 'Aros' or 'Acos' to get the correct node * @return \Cake\ORM\Query * @link https://book.cakephp.org/2.0/en/core-libraries/behaviors/acl.html#node * @throws \Cake\Core\Exception\Exception @@ -113,7 +114,12 @@ public function node($ref = null, $type = null) throw new Exception\Exception(__d('cake_dev', 'ref parameter must be a string or an Entity')); } - return $this->_table->{$type}->node($ref); + if(property_exists($this->_table, $type)){ + return $this->_table->{$type}->node($ref); + }else{ + $type = Inflector::pluralize($type); + return $this->_table->{$type}->node($ref); + } } /** @@ -131,6 +137,7 @@ public function afterSave(Event $event, Entity $entity) $types = [$types]; } foreach ($types as $type) { + $type = Inflector::pluralize($type); $parent = $entity->parentNode(); if (!empty($parent)) { $parent = $this->node($parent, $type)->first(); @@ -171,6 +178,7 @@ public function afterDelete(Event $event, Entity $entity) $types = [$types]; } foreach ($types as $type) { + $type = Inflector::pluralize($type); $node = $this->node($entity, $type)->toArray(); if (!empty($node)) { $event->getSubject()->{$type}->delete($node[0]); diff --git a/src/Model/Table/AcoActionsTable.php b/src/Model/Table/AcoActionsTable.php index 17744dfc..1b9f2c6f 100644 --- a/src/Model/Table/AcoActionsTable.php +++ b/src/Model/Table/AcoActionsTable.php @@ -34,7 +34,7 @@ class AcoActionsTable extends Table public function initialize(array $config) :void { $this->belongsTo('Acos', [ - 'className' => App::className('Acl.AcosTable', 'Model/Table'), + 'className' => 'Acl.Acos' ]); } } diff --git a/src/Model/Table/AcosTable.php b/src/Model/Table/AcosTable.php index f99ed732..69795ade 100644 --- a/src/Model/Table/AcosTable.php +++ b/src/Model/Table/AcosTable.php @@ -39,13 +39,13 @@ public function initialize(array $config) :void $this->addBehavior('Tree', ['type' => 'nested']); $this->belongsToMany('Aros', [ - 'through' => App::className('Acl.PermissionsTable', 'Model/Table'), - 'className' => App::className('Acl.ArosTable', 'Model/Table'), + 'through' => 'Acl.Permissions', + 'className' => 'Acl.Aros', ]); $this->hasMany('AcoChildren', [ - 'className' => App::className('Acl.AcosTable', 'Model/Table'), + 'className' => 'Acl.Acos', 'foreignKey' => 'parent_id', ]); - $this->setEntityClass(App::className('Acl.Aco', 'Model/Entity')); + $this->setEntityClass('Acl.Aco'); } } diff --git a/src/Model/Table/ArosTable.php b/src/Model/Table/ArosTable.php index 68c424d0..f5af0683 100644 --- a/src/Model/Table/ArosTable.php +++ b/src/Model/Table/ArosTable.php @@ -39,11 +39,11 @@ public function initialize(array $config) :void $this->addBehavior('Tree', ['type' => 'nested']); $this->belongsToMany('Acos', [ - 'through' => App::className('Acl.PermissionsTable', 'Model/Table'), - 'className' => App::className('Acl.AcosTable', 'Model/Table'), + 'through' => 'Acl.Permissions', + 'className' => 'Acl.Acos', ]); $this->hasMany('AroChildren', [ - 'className' => App::className('Acl.ArosTable', 'Model/Table'), + 'className' => 'Acl.Aros', 'foreignKey' => 'parent_id', ]); diff --git a/src/Model/Table/PermissionsTable.php b/src/Model/Table/PermissionsTable.php index 238cffb1..4549be46 100644 --- a/src/Model/Table/PermissionsTable.php +++ b/src/Model/Table/PermissionsTable.php @@ -43,10 +43,10 @@ public function initialize(array $config) :void $this->setAlias('Permissions'); $this->setTable('aros_acos'); $this->belongsTo('Aros', [ - 'className' => App::className('Acl.ArosTable', 'Model/Table'), + 'className' => 'Acl.Aros' ]); $this->belongsTo('Acos', [ - 'className' => App::className('Acl.AcosTable', 'Model/Table'), + 'className' => 'Acl.Acos' ]); $this->Aro = $this->Aros->getTarget(); $this->Aco = $this->Acos->getTarget();