コード例 #1
0
 /**
  * Creates a new Service model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Service();
     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
 /**
  *新增和修改提交
  * @return array
  */
 public function actionSubmit()
 {
     $params = Yii::$app->request->post();
     $model = new Service();
     $params["create_at"] = date("Y-m-d");
     $params["user_id"] = Yii::$app->user->getId();
     $params["status"] = 0;
     $data = array();
     //yii自动生成的form参数是Enterprise["name"]这种形式,获取后就会是在一个Enterprise中
     $data["Service"] = $params;
     \Yii::$app->response->format = \yii\web\Response::FORMAT_JSON;
     if ($model->load($data) && $model->save()) {
         return ["success" => true];
     } else {
         return ["success" => false, "error_code" => 1];
     }
 }