Exemple #1
0
 protected function findModel($id)
 {
     if (($model = Profile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function save()
 {
     if ($this->validate()) {
         $isValid = false;
         $this->imageFile = UploadedFile::getInstance($this, 'imageFile');
         $user = User::findOne(Yii::$app->user->getId());
         if (isset($user->profile)) {
             $profile = Profile::findOne($user->profile->id);
         } else {
             $profile = new Profile();
         }
         if (isset($this->imageFile)) {
             $imagePath = '/uploads/' . $this->imageFile->baseName . '.' . $this->imageFile->extension;
             $this->imageFile->saveAs(Yii::getAlias('@webroot') . $imagePath);
             $m_image = new Image();
             $m_image->url = $imagePath;
             if ($m_image->save()) {
                 $image = Image::findOne($m_image->getPrimaryKey());
                 $profile->link('image', $image);
                 $isValid = true;
             } else {
                 $isValid = false;
             }
         }
         $profile->firstname = $this->firstname;
         $profile->lastname = $this->lastname;
         $profile->aboutme = $this->aboutme;
         $profile->link('user', $user);
         if ($profile->save()) {
             $isValid = true;
         } else {
             $isValid = false;
         }
         return $isValid;
     } else {
         return false;
     }
 }
 /**
  * Finds the Profile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Profile the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Profile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрошенной страницы не существует.');
     }
 }
 /**
  * Finds the Profile model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Profile the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Profile::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('Запрашиваемая страница не найдена.');
     }
 }
 public function actionIndex()
 {
     $name = Profile::findOne(['user_id' => Yii::$app->user->identity->id]);
     return $this->render('index', ['name' => $name]);
 }