The save method cannot be called in the ThinkPHP model class-PHP development

Source: Internet
Author: User
These days, due to work needs, we create a membership Module Based on WBlog3.12. During the test and update of the member profile picture, thinkphp encountered a problem: the module model class cannot execute the update query statement! The following is a piece of code for updating data. The uploaded profile picture is successful. $ uploadList [0] [savename] is the name of the saved image obtained when the profile picture is updated, during debugging, make sure that the value of $ data [thumb] is not empty. The Code is as follows: Create a member Module Based on WBlog3.12 due to work needs these days.


A ThinkPHP problem was found during the test of updating the Member's profile picture:In the module model class, the update query statement cannot be executed!
The following is a piece of code for updating data. The uploaded avatar is successful. $ uploadList [0] ['savename'] indicates the name of the image that is successfully obtained when the Avatar is updated, during debugging, make sure that the value of $ data ['thumb'] is not empty. The Code is as follows:

Class AttachModel extends Model {... $ data ['thumb'] = $ uploadList [0] ['savename']; // obtain the name of the updated avatar. save $ list = M ('member ') -> where (array ('id' => 1)-> save ($ data );}

The above Code does not seem to have any errors. I think so, but it also takes me a lot of time to find errors in other code because it does not seem to have any errors, in the end, the problem occurs in the code snippet above -- put it in the controller, and the problem is solved. Haha, the test results are so painful!
After testing, it is okay to add data to the model class, that is, the above Code can be executed in this way.

Class AttachModel extends Model {... $ data ['thumb'] = $ uploadList [0] ['savename']; // obtain the name of the updated avatar. save $ list = M ('member ') -> where (array ('id' => 1)-> add ($ data); // save ($ data) change to add ($ data )...}

I checked the model class of the ThinkPHP core package. The class contains the add and save methods. As for the failure to execute save in the module model class, I am still confused, but at least it will not write the save in the model class.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.