当前位置: 首页>>代码示例>>PHP>>正文


PHP Role::findOne方法代码示例

本文整理汇总了PHP中app\models\Role::findOne方法的典型用法代码示例。如果您正苦于以下问题:PHP Role::findOne方法的具体用法?PHP Role::findOne怎么用?PHP Role::findOne使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\models\Role的用法示例。


在下文中一共展示了Role::findOne方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: execute

 public function execute($user, $item, $params)
 {
     if (!Yii::$app->user->isGuest) {
         $group = Yii::$app->user->identity->role_id;
         // получаем id Модератора из таблицы Role
         $moder_id = Role::getIdByName('moderator');
         // получаем id Писателя из таблицы Role
         $writer_id = Role::getIdByName('writer');
         if ($item->name === 'moderator') {
             return $group == $moder_id;
         } elseif ($item->name === 'writer') {
             $role = Role::findOne(['name' => 'moderator']);
             return $group == $moder_id || $group == $writer_id;
         }
     }
     return FALSE;
 }
开发者ID:silischev,项目名称:yii2_blog,代码行数:17,代码来源:UserGroupRule.php

示例2: actionUpdateRole

 public function actionUpdateRole()
 {
     if ($this->isUpdateAllowed()) {
         if (Yii::$app->request->post()) {
             $role = Role::findOne(Yii::$app->request->get()['id']);
             $role->name = Yii::$app->request->post()['role'];
             $role->update();
             $rowsDeleted = RoleModule::deleteAll('role = ' . Yii::$app->request->get()['id']);
             $roleModel = new Role();
             $roleModel->updateRole(Yii::$app->request->get()['id'], Yii::$app->request->post());
             /*return $this->render('role_list');*/
             return $this->redirect(['security/role-management']);
         }
         return $this->render('update_role');
     } else {
         echo "You don't have access here";
         die;
     }
 }
开发者ID:tiyolab,项目名称:autocom,代码行数:19,代码来源:SecurityController.php

示例3: findModel

 /**
  * Finds the Role model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Role the loaded model
  * @throws HttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Role::findOne($id)) !== null) {
         return $model;
     } else {
         throw new HttpException(404, 'The requested page does not exist.');
     }
 }
开发者ID:febfeb,项目名称:yii2-basic-ready,代码行数:15,代码来源:RoleController.php

示例4: getNameById

 public static function getNameById($id)
 {
     $role = Role::findOne(['id' => $id]);
     return $role->name;
 }
开发者ID:silischev,项目名称:yii2_blog,代码行数:5,代码来源:Role.php

示例5: actionParsingLog

 public function actionParsingLog($id)
 {
     $mod = LogUpload::findOne($id);
     $type = $mod->type;
     $keys = \yii\helpers\Json::decode($mod->keys);
     $values = \yii\helpers\Json::decode($mod->values);
     $modelAttribute = new Role();
     $not = Util::excelNot();
     foreach ($values as $value) {
         if ($type == LogUpload::TYPE_INSERT) {
             $model = new Role();
         } else {
             $model = Role::findOne($value['id']);
         }
         foreach ($keys as $v) {
             $model->{$v} = $value[$v];
         }
         $e = 0;
         if ($model->save()) {
             $model = NULL;
             $pos = NULL;
         } else {
             $error[] = \yii\helpers\Json::encode($model->getErrors());
             $e = 1;
         }
     }
     if ($error) {
         foreach ($error as $err) {
             if ($err) {
                 $er[] = $err;
                 $e += 1;
             }
         }
         if ($e) {
             $mod->warning = \yii\helpers\Json::encode($er);
             $mod->save();
             echo '<pre>';
             print_r($er);
         }
     }
 }
开发者ID:sintret,项目名称:yii2-basic-sintret,代码行数:41,代码来源:RoleController.php

示例6: getRoleName

 public function getRoleName($roleId)
 {
     return Role::findOne($roleId)->name;
 }
开发者ID:romangrb,项目名称:resource-registry,代码行数:4,代码来源:UserRoleView.php


注:本文中的app\models\Role::findOne方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。