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.