예제 #1
0
 /**
  * Creates a new Company model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Company();
     if ($model->load(Yii::$app->request->post()) && $model->save()) {
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 public function actionUpdate($id = 0)
 {
     //      $out = ['status' => 'err', 'error' => 'Unknown error'];
     if (\Yii::$app->user->isGuest) {
         throw new NotFoundHttpException();
     }
     $r = new Request();
     if ($r->post('Company')['id']) {
         $id = $r->post('Company')['id'];
     }
     //      vd($r->post('Company'));
     $userID = \Yii::$app->user->getId();
     if ($id) {
         $company = Company::findOne(['id' => $id, 'user_id' => $userID]);
     } else {
         $company = new Company();
         //        \Yii::$app->session->setFlash('error', 'Company ID is required.');
         //        $this->redirect(array('view','id'=>$company));
         //        $this->redirect(array('index'));
         //        return;
     }
     //        vd($company);
     if ($company) {
         if ($company->load($r->post())) {
             $company->user_id = $userID;
             if ($company->validate() && $company->save()) {
                 //vd([$r->post(),$order->attributes]);
                 //          $out = [
                 //            'status' => 'ok',
                 //            'order' => $order->id,
                 //            'user' => $order->user_id,
                 //            'sum' => $order->price / 100,
                 //          ];
                 //          $this->redirect(array('view','id'=>$company));
             } else {
                 //          vd($company->errors);
                 \Yii::$app->session->setFlash('error', array_values($company->errors)[0][0]);
                 //          $out['error'] = array_values($order->errors)[0][0];
                 //vd($order->errors);
             }
         }
     } else {
         \Yii::$app->session->setFlash('error', 'Такой компании не существует');
         $this->redirect(array('index'));
         return;
     }
     return $this->render('update', ['company' => $company]);
     //      \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     //      return $out;
     /*vd(['get' => $r->getQueryParams() ,
       'post' => $r->post(),
       'order' => $order],1); //*/
 }
예제 #3
0
 /**
  * Creates a new Company model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Company();
     if ($model->load(Yii::$app->request->post())) {
         $model->save();
         $company_id = $model->id;
         $user_id = Yii::$app->user->id;
         $contact = new Contact();
         $contact->company_id = $company_id;
         $contact->user_id = $user_id;
         $contact->roles_code = Roles::ROLE_EMP;
         if (!$contact->save()) {
             throw new NotFoundHttpException('Save contact error');
         }
         return $this->redirect(['view', 'id' => $model->id]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }