response->format=Response::FORMAT_JSON;"; 2. Check whether the data passes the model's validation rules and print it before saving. Verification results."/> response->format=Response::FORMAT_JSON;"; 2. Check whether the data passes the model's validation rules and print it before saving. Verification results.">
Home > Article > PHP Framework > What should I do if yii save cannot save data?
Yii save cannot save data solution: 1. Remove the statement "Yii::$app->response->format=Response::FORMAT_JSON;"; 2. Check whether the data passes the model verification rules, and print the verification results before saving.
What should I do if yii save cannot save data?
Recommendation: "yii Tutorial"
## Specific questions:
Yii2 save failed to save [2.0 version]public function actionIndex() { $session = Yii::$app->session; Yii::$app->response->format=Response::FORMAT_JSON; $model = new PostSendInfo(); // $post = Yii::$app->request->post(); $post=['company_name'=>'123','mobile_phone'=>12,'sender_dep'=>'2323']; if ($post) { $model->login_id = $session['login_id']; $model->case_id = "1"; $model->ems_id = "2"; $model->create_time = date('Y-m-d H:i:s',time()); $model->setAttributes($post); if($model->save()){ return "保存成功!"; } return "保存失败!"; } return "保存失败!"; }$post value failed to save
Solution:
Two problems:1,Yii::$app->response->format=Response::FORMAT_JSON; This sentence is used when returning json and should be removed here.
The above is the detailed content of What should I do if yii save cannot save data?. For more information, please follow other related articles on the PHP Chinese website!