yii\rbac\PhpManager::addChild PHP Метод

addChild() публичный Метод

public addChild ( $parent, $child )
    public function addChild($parent, $child)
    {
        if (!isset($this->items[$parent->name], $this->items[$child->name])) {
            throw new InvalidParamException("Either '{$parent->name}' or '{$child->name}' does not exist.");
        }
        if ($parent->name === $child->name) {
            throw new InvalidParamException("Cannot add '{$parent->name} ' as a child of itself.");
        }
        if ($parent instanceof Permission && $child instanceof Role) {
            throw new InvalidParamException('Cannot add a role as a child of a permission.');
        }
        if ($this->detectLoop($parent, $child)) {
            throw new InvalidCallException("Cannot add '{$child->name}' as a child of '{$parent->name}'. A loop has been detected.");
        }
        if (isset($this->children[$parent->name][$child->name])) {
            throw new InvalidCallException("The item '{$parent->name}' already has a child '{$child->name}'.");
        }
        $this->children[$parent->name][$child->name] = $this->items[$child->name];
        $this->saveItems();
        return true;
    }

Usage Example

Пример #1
0
 /**
  * Initial RBAC action
  * @param integer $id Superadmin ID
  */
 public function actionInit($id = null)
 {
     $auth = new PhpManager();
     $auth->init();
     $auth->removeAll();
     //удаляем старые данные
     // Rules
     $groupRule = new GroupRule();
     $auth->add($groupRule);
     // Roles
     $user = $auth->createRole('user');
     $user->description = 'User';
     $user->ruleName = $groupRule->name;
     $auth->add($user);
     $moderator = $auth->createRole('moderator');
     $moderator->description = 'Moderator';
     $moderator->ruleName = $groupRule->name;
     $auth->add($moderator);
     $auth->addChild($moderator, $user);
     $admin = $auth->createRole('admin');
     $admin->description = 'Admin';
     $admin->ruleName = $groupRule->name;
     $auth->add($admin);
     $auth->addChild($admin, $moderator);
     // $auth->assign($admin, 1);
 }
All Usage Examples Of yii\rbac\PhpManager::addChild