public function actionUpdateProfile($id) { \yii\helpers\Url::remember('', 'actions-redirect'); $user = $this->findModel($id); $profile = \backend\models\Profile::findOne(['user_id' => $user->id]); if ($profile == null) { $profile = Yii::createObject(\backend\models\Profile::className()); $profile->link('user', $user); } $this->performAjaxValidation($profile); if ($profile->load(Yii::$app->request->post())) { $profile->fileProfile = \yii\web\UploadedFile::getInstance($profile, 'fileProfile'); $save_fileProfile = ''; if ($profile->fileProfile) { $imagepath = 'uploads/profile/'; // Create folder under web/uploads/logo $profile->image_profile = $imagepath . rand(10, 100) . '-' . $profile->fileProfile->name; $save_fileProfile = 1; } if ($profile->save()) { if ($save_fileProfile) { $profile->fileProfile->saveAs($profile->image_profile); } else { echo 'ada yang salah'; } Yii::$app->getSession()->setFlash('success', Yii::t('user', 'Profile details have been updated')); return $this->refresh(); } } return $this->render('_profile', ['user' => $user, 'profile' => $profile]); }
public function actionProfile() { $model = ($model = Profile::findOne(Yii::$app->user->id)) ? $model : new Profile(); if ($model->load(Yii::$app->request->post()) && $model->validate()) { if ($model->updateProfile()) { Yii::$app->session->setFlash('success', 'Профиль изменен'); } else { Yii::$app->session->setFlash('error', 'Профиль не изменен'); Yii::error('Ошибка записи. Профиль не изменен'); return $this->refresh(); } } return $this->render('profile', ['model' => $model]); }
public function getProfile() { return $this->hasOne(Profile::className(), ['user_id' => 'id']); }