How to solve the problem of thinkphp save failure
This article mainly explains "how to solve the problem of thinkphp save failure". The content of the article is simple and clear, and it is easy to learn and understand. Please follow the editor's train of thought to study and learn "how to solve the problem of thinkphp save failure".
The solution to thinkphp save failure: 1, open the corresponding code file; 2, use "$this- > typeModel- > field ('id,name,sort')-> data ($data)-> save ();" to update the data.
This article operating environment: Windows7 system, thinkphp v5.1, Dell G3 computer.
How to solve the problem of thinkphp save failure?
Failed to update thinkphp save ()
I. failure cases
$data = I (); $rs = $this- > typeModel- > data ($data)-> save ()
II. Correct cases
Correct one: rs=$this- > typeModel- > field ('id,name,sort')-> data ($data)-> save (); correct 2: / / $rs=$this- > typeModel- > where (' id='.$data ['id'])-> field (' name,sort')-> data ($data)-> save (); correct 3: / / $rs=M ('CityCategory')-> where (' id='.$data ['id'])-> field (' name,sort')-> data ($data)-> save (); / Note: / / 1. If the new data is the same as the original data, it will be the same as the new failure / / 2. No field restriction will result in modification failure / / 3. You need to write the primary key id and the field to be changed in field, or write the primary key id in the where condition.
Third, cause analysis
All the fields id pid name path sort in the value $data received from the foreground have values, but some of the new data is the same as the old data.
When the new data and the old data have the same field data, you need to use field to determine the data that needs to be changed. It is estimated that it will be updated even if it is the same in field.
Thank you for your reading, the above is the content of "how to solve the problem of thinkphp save failure", after the study of this article, I believe you have a deeper understanding of how to solve the problem of thinkphp save failure, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!