Exemple #1
0
 public function actionCreate()
 {
     $model = new User();
     if ($model->load(Yii::$app->request->post())) {
         $model->generatePassword($model->password);
         $model->status = 1;
         $model->created_at = time();
         $model->updated_at = time();
         if ($model->validate()) {
             $model->save();
             $image = UploadedFile::getInstance($model, 'image');
             $model->image = md5(time()) . '.' . $image->extension;
             $image->saveAs(Yii::getAlias('@frontend') . '/web/image/' . $model->image);
             $authManager = Yii::$app->authManager;
             $role = $authManager->getRole(\common\constants\UserType::getUserTypeText($model->user_type));
             $authManager->assign($role, $model->id);
             return $this->redirect(['view', 'id' => $model->id]);
         }
         echo '<pre>';
         print_r($model->errors);
         echo '</pre>';
         throw new Exception("Неудачка");
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }