/** * Validate user model * * @throws NotFoundHttpException */ public function init() { if (!$this->model instanceof User && $this->userId) { $userId = is_scalar($this->userId) ? (int) $this->userId : 0; $this->model = User::findOne($userId); } if (!$this->model instanceof User) { throw new NotFoundHttpException(); } $this->userModule = Yii::$app->getModule('user'); parent::init(); }
public function actionNotifications($id = 0) { if (Yii::$app->request->get('id') == 0 && !Yii::$app->getUser()->getIsGuest()) { $id = Yii::$app->getUser()->getIdentity()->getId(); } /** @var User $user */ $user = User::findOne(['id' => $id]); if (!$user || !Yii::$app->getUser()->can('updateProfile', ['user' => $user])) { throw new NotFoundHttpException(); } $model = new NotifyForm(); if ($model->load(Yii::$app->request->post())) { if ($model->validate()) { $user->notify_mention_email = (int) $model->notify_mention_email; $user->notify_mention_web = (int) $model->notify_mention_web; $user->save(); } } else { $model->notify_mention_email = $user->notify_mention_email; $model->notify_mention_web = $user->notify_mention_web; } return $this->render('notifications', ['user' => $user, 'model' => $model]); }
/** * Finds user model by the form given username. * @return User|null current user model. * If null, it means the current user model will be not found with this username. */ public function getUser() { if (!isset($this->_user)) { if ($this->scenario == 'email') { $this->_user = User::findByEmail($this->email); } elseif ($this->scenario == 'token') { $this->_user = User::findOne(['password_change_token' => $this->token]); } } return $this->_user; }
/** * Finds the User model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return User the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = User::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
/** * @param integer $id user profile identificator * @return string content */ public function actionView($id) { $user = User::findOne(['id' => $id]); return $this->render('view', ['user' => $user]); }