Пример #1
0
 /**
  * Signs company up.
  *
  * @return User|null the saved model or null if saving fails
  */
 public function signupCompany()
 {
     if ($this->validate()) {
         $user = new User();
         $user->username = $this->name;
         $user->email = $this->email;
         $user->phone = $this->phone;
         $user->setPassword($this->password);
         $user->generateAuthKey();
         $check_user = $user->save();
         $service = new Service();
         $service->category_id = $this->category_id;
         $service->owner = $user->id;
         $service->name = $this->name;
         $service->phone = $this->phone;
         $service->description = $this->description;
         $check_service = $service->save();
         if ($check_user && $check_service) {
             return $user;
         }
         VarDumper::dump($service->getErrors(), 6, 1);
         die;
     }
     return null;
 }
Пример #2
0
 /**
  * Creates a new Service model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     session_start();
     $_SESSION['Service']['id'] = Service::find()->max('id') + 1;
     $model = new Service();
     $media = Media::find()->where(['service_id' => $_SESSION['Service']['id']])->all();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model, 'media' => $media]);
     }
 }