/** * Finds the AuthItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return AuthItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AuthItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('Страница не найдена.'); } }
/** * Finds the AuthItem model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return AuthItem the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = AuthItem::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @inheritdoc * Добавление связи роль=>пользователь в таблицу auth_assignment (RBAC) */ public function afterSave($insert, $changedAttributes) { parent::afterSave($insert, $changedAttributes); AuthAssignment::deleteAll(['user_id' => $this->id]); /** @var \common\models\AuthItem $role */ $role = AuthItem::findOne($this->role_id); if ($role) { $assign = new AuthAssignment(); $assign->user_id = (string) $this->id; $assign->item_name = $role->name; $assign->created_at = time(); $assign->save(); } return true; }