Exemple #1
0
 public function actionRegister()
 {
     $model = new User(['scenario' => User::SCENARIO_REGISTER]);
     if (\Yii::$app->request->isPost and $model->load(\Yii::$app->request->post())) {
         $model->imageAvatar = UploadedFile::getInstance($model, 'imageAvatar');
         if ($model->validate()) {
             if ($model->imageAvatar) {
                 $model->imageAvatar->saveAs('image/avatar/' . $model->login . '.jpg');
                 $model->avatar = $model->login . '.jpg';
                 $imagine = Image::thumbnail("image/avatar/" . $model->login . ".jpg", 150, 150)->save("image/avatar/mini-" . $model->login . ".jpg");
                 $model->imageAvatar = '';
             }
             $model->save();
             \Yii::$app->user->login($model);
             \Yii::$app->response->redirect('/site/index')->send();
         }
     }
     return $this->render('register.tpl', array('model' => $model));
 }