Thinkphp field Cache

Source: Internet
Author: User
Today, I made some secondary development changes to the program developed by the thinkphp framework. Some of the changes were made to the data structure, and several new fields were added. I called M ('xxx')-add ($ data )? When you insert a value, the newly added field data is always inserted, and each time it is the default value. I keep searching to see if the statement is wrong. Why .? Later, the model

Today, I made some secondary development changes to the program developed by the thinkphp framework. Some of the changes were made to the data structure, and several new fields were added. I called M ('xxx')-add ($ data )? When you insert a value, the newly added field data is always inserted, and each time it is the default value. I keep searching to see if the statement is wrong. Why .? Later, the model

Today, I made some secondary development changes to the program developed by the thinkphp framework. Some of the changes were made to the data structure, and several new fields were added. I called M ('xxx')-> add ($ data )? When you insert a value, the newly added field data is always inserted, and each time it is the default value. I keep searching to see if the statement is wrong. Why .? Later, I printed the model object and checked it carefully. I found that his protected: member variable $ fields? The field information does not contain the new field name I just added .? So suddenly -- cache ...?? Clear cache. finally, the data can be inserted normally. if the field cache setting is not disabled in the configuration file of the original TP, it is enabled by default. As long as it is run, it will cache the data field information ~ Runtime/Data/_ files? Folder and store it in an array .??? Protected $ fields = array (....); Of course, you can also manually define the name of the data table field in the model class to avoid IO loading efficiency overhead. Simply add the fields attribute to the model class. The definition format is as follows :? Class UserModel extends Model {protected $ fields = array ('id', 'username', 'email ', 'age',' _ pK' => 'id ', '_ autoinc' => true)} Where _ pk indicates the primary key field name _ autoinc indicates whether the primary key automatically grows. You can set the DB_FIELDS_CACHE parameter to disable automatic field caching, if you change the database structure frequently during development without caching the data table fields, you can add the following configuration in the project configuration file: Write this section in config. in php? 'Db _ FIELDS_CACHE '=> false var ujian_config = {'num': 6, 'showtype': 2, [...]

Original article address: Thinkphp field cache. Thank you for sharing it.

Related Article

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.