本文整理汇总了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;
}
示例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;
}
}
示例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.');
}
}
示例4: getNameById
public static function getNameById($id)
{
$role = Role::findOne(['id' => $id]);
return $role->name;
}
示例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);
}
}
}
示例6: getRoleName
public function getRoleName($roleId)
{
return Role::findOne($roleId)->name;
}