public function actionAvatar()
 {
     $profile = $this->findProfile();
     $avatars = Avatar::find()->all();
     if ($profile->load(Yii::$app->request->post()) && $profile->save()) {
         Yii::$app->session->setFlash('success', 'Аватар успешно изменен');
         return $this->redirect(['index']);
     }
     return $this->render('avatar', ['current' => $profile, 'avatars' => $avatars]);
 }
Beispiel #2
0
 /**
  * 获取用户头像,(如果无数据则返回默认头像)
  * @return mixed
  */
 public function getAvatarUrl()
 {
     $avatar = $this->avatar;
     return $avatar ? $avatar->getUrl() : Avatar::getDefaultUrl();
 }
 /**
  * Finds the Avatar model based on its primary key value.
  * If the model is not found, a 404 HTTP exception will be thrown.
  * @param integer $id
  * @return Avatar the loaded model
  * @throws NotFoundHttpException if the model cannot be found
  */
 protected function findModel($id)
 {
     if (($model = Avatar::findOne($id)) !== null) {
         return $model;
     } else {
         throw new NotFoundHttpException('The requested page does not exist.');
     }
 }
 public function down()
 {
     $this->dropTable(User::tableName());
     $this->dropTable(Avatar::tableName());
     $this->dropTable(Meta::tableName());
 }
Beispiel #5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getAvatar()
 {
     return $this->hasOne(Avatar::className(), ['id' => 'avatar_id']);
 }