yii\rbac\DbManager::init PHP Method

init() public method

This method overrides the parent implementation by establishing the database connection.
public init ( )
    public function init()
    {
        parent::init();
        $this->db = Instance::ensure($this->db, Connection::className());
        if ($this->cache !== null) {
            $this->cache = Instance::ensure($this->cache, Cache::className());
        }
    }

Usage Example

コード例 #1
0
ファイル: RbacController.php プロジェクト: Abzal/onlinelearn
 /**
  * Initial RBAC action
  * @param integer $id Superadmin ID
  */
 public function actionInit($id = null)
 {
     $auth = new DbManager();
     $auth->init();
     $auth->removeAll();
     //удаляем старые данные
     // Rules
     $groupRule = new GroupRule();
     $auth->add($groupRule);
     // Roles
     $student = $auth->createRole('student');
     $student->description = 'Student';
     $student->ruleName = $groupRule->name;
     $auth->add($student);
     $teacher = $auth->createRole('teacher');
     $teacher->description = 'Teacher';
     $teacher->ruleName = $groupRule->name;
     $auth->add($teacher);
     $auth->addChild($teacher, $student);
     $admin = $auth->createRole('admin');
     $admin->description = 'Admin';
     $admin->ruleName = $groupRule->name;
     $auth->add($admin);
     $auth->addChild($admin, $teacher);
     $superadmin = $auth->createRole('superadmin');
     $superadmin->description = 'Superadmin';
     $superadmin->ruleName = $groupRule->name;
     $auth->add($superadmin);
     $auth->addChild($superadmin, $admin);
     // Superadmin assignments
     if ($id !== null) {
         $auth->assign($superadmin, $id);
     }
 }
All Usage Examples Of yii\rbac\DbManager::init