Пример #1
0
 /**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Profile();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
 /**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     if (Yii::$app->user->can('create-profile')) {
         $model = new Profile();
         if ($model->load(Yii::$app->request->post())) {
             //get the instance of the uploaded file
             $imageName = $model->profile_firstname;
             $model->file = UploadedFile::getInstance($model, 'file');
             $model->file->saveAs('uploads/' . $imageName . '.' . $model->file->extension);
             //save the path in the db column
             $model->profile_profile = 'uploads/' . $imageName . '.' . $model->file->extension;
             $model->save();
             return $this->redirect(['view', 'id' => $model->profile_id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } else {
         throw new ForbiddenHttpException();
     }
 }
Пример #3
0
 /**
  * Creates a new Profile model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Profile();
     $user = new User();
     if ($model->load(Yii::$app->request->post()) && $user->load(yii::$app->request->post())) {
         $user->password_hash = Yii::$app->security->generatePasswordHash($user->password_hash);
         $user->auth_key = Yii::$app->security->generateRandomString();
         if ($user->save()) {
             $file = UploadedFile::getInstance($model, 'profile_img');
             if ($file->size != 0) {
                 $model->photo = $user->id . '.' . $file->extension;
                 $file->saveAs('uploads/profile/' . $user->id . '.' . $file->extension);
             }
             $model->user_id = $user->id;
             $model->save();
         }
         return $this->redirect(['view', 'id' => $model->user_id]);
     } else {
         return $this->render('create', ['model' => $model, 'user' => $user]);
     }
 }
Пример #4
0
 public function actionForm()
 {
     //vd(1);
     $model = Profile::find()->where(['user_id' => Yii::$app->user->id])->one();
     if (!$model) {
         $model = new Profile();
     }
     if ($model->load(Yii::$app->request->post())) {
         //vd($_POST);
         if ($model->validate()) {
             $model->gender = $_POST['gender'];
             $model->user_id = Yii::$app->user->id;
             $model->login = User::getLoginById(Yii::$app->user->id);
             $model->save();
             return $this->render('form', ['model' => $model]);
         } else {
             vd($model->getErrors());
         }
     }
     return $this->render('form', ['model' => $model]);
 }
 public function actionProfile()
 {
     $model = Profile::findOne(['user_id' => Yii::$app->user->id]);
     if (!$model) {
         $model = new Profile();
         $model->user_id = Yii::$app->user->id;
     }
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New password was saved.'));
         return $this->goHome();
     }
     return $this->render('profile', ['model' => $model]);
 }
Пример #6
0
 public function actionProfile()
 {
     $model = Profile::findOne(['user_id' => Yii::$app->user->id]);
     if (!$model) {
         $model = new Profile();
         $model->user_id = Yii::$app->user->id;
     }
     if ($model->birthday) {
         $model->year = substr($model->birthday, 0, 4);
         $model->month = substr($model->birthday, 5, 2);
         $model->day = substr($model->birthday, 8, 2);
     }
     if ($model->load(Yii::$app->request->post())) {
         $model->year = intval(Yii::$app->request->post()['Profile']['year']);
         $model->month = intval(Yii::$app->request->post()['Profile']['month']);
         $model->day = intval(Yii::$app->request->post()['Profile']['day']);
         if ($model->year || $model->month || $model->day) {
             $model->birthday = date('Y-m-d H:i:s', mktime(0, 0, 0, $model->month, $model->day, $model->year));
         }
         if ($model->save()) {
             Yii::$app->getSession()->setFlash('success', Yii::t('app', 'New profile was saved.'));
         }
     }
     return $this->render('profile', ['model' => $model]);
 }