예제 #1
0
 /**
  * Creates a new Customer model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate($id)
 {
     $model = new Customer();
     if ($model->load(Yii::$app->request->post())) {
         if ($model->save()) {
             //return $this->redirect(['view', 'id' => $model->id]);
             Yii::$app->response->format = Response::FORMAT_JSON;
             $result = ['status' => "1", 'message' => $model->id];
             return $result;
         } else {
             Yii::$app->response->format = Response::FORMAT_JSON;
             $result = ['status' => "0", 'message' => 'error'];
             return $result;
         }
         if ($model->load(Yii::$app->request->post()) && $model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             return $this->render('create', ['model' => $model]);
         }
     } elseif (Yii::$app->request->isAjax) {
         return $this->renderAjax('_form', ['model' => $model]);
     } else {
         return $this->render('create', ['model' => $model]);
     }
 }
예제 #2
0
 /**
  * Creates a new Customer model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Customer();
     $user = UserAccount::find()->select('id, username')->all();
     if ($model->load(Yii::$app->request->post())) {
         $model->created_at = date("Y-m-d H:i:s");
         $model->updated_at = date("Y-m-d H:i:s");
         $model->token_expired = date('Y-m-d H:i:s', strtotime($model->token_expired));
         if ($model->save()) {
             return $this->redirect(['view', 'id' => $model->id]);
         } else {
             // print_r($model->errors);
             return $this->render('create', ['model' => $model, 'user' => $user]);
         }
     } else {
         return $this->render('create', ['model' => $model, 'user' => $user]);
     }
 }