/**
  * Creates a new AdminRole model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @throws UserError if this model generate errors.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new AdminRole();
     $identity = $this->user->identity;
     if ($this->isPost) {
         $model->attributes = $this->request->post($model->formName(), []);
         $model->admin_id = $identity->id;
         $model->admin_path = $identity->parent_path . $identity->id;
         if ($model->save()) {
             if (Yii::$app->response->acceptMimeType == 'application/json') {
                 return ['pk' => $model->id, 'data' => $model->toArray()];
             } elseif (Yii::$app->response->acceptMimeType == 'text/grid') {
                 return $this->search(['id' => $model->id]);
             } else {
                 return $this->redirect(['index']);
             }
         } else {
             if ($this->isAjax) {
                 throw new UserError($model->getErrors());
             } else {
                 goto REN;
             }
         }
     } else {
         REN:
         return $this->render('create', ['model' => $model, 'displayAcls' => Yii::$app->menu->displayAcls($identity->admin_role_id)]);
     }
 }
Example #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Model::unguard();
     // Admin
     DB::table('admins')->truncate();
     $admin = new Admin();
     $admins = array(array('email' => '*****@*****.**', 'name' => 'Admin', 'password' => 'admin', 'avatar' => 'http://tp3.sinaimg.cn/1812747674/180/5606472968/1'));
     foreach ($admins as $admin) {
         $admin = new Admin($admin);
         $admin->save();
     }
     // Admin Role
     DB::table('admin_roles')->truncate();
     $adminrole = new AdminRole();
     $super_admin = new AdminRole(array('role_name' => 'Administrator', 'role_scopes' => ['all']));
     $super_admin->save();
     $admin->roles()->attach($super_admin);
 }