今天在应用thinkphp框架开发的程序做些二次开发修改, 其中有改动到数据结构,新增了几个字段. 调用 M(‘xxx’)-add($data)? 插入值时,新增的字段数据总是插入不进去,每次都是默认的值, 一直找看是不是什么语句写错了, 找了半天也没出个所以然来.? 后来将模型
今天在应用thinkphp框架开发的程序做些二次开发修改, 其中有改动到数据结构,新增了几个字段. 调用 M(‘xxx’)->add($data)? 插入值时,新增的字段数据总是插入不进去,每次都是默认的值, 一直找看是不是什么语句写错了, 找了半天也没出个所以然来.? 后来将模型对象打印出来仔细查看,发现-他的 protected :成员变量 $fields? 字段信息 中没有我刚才添加的新字段名称.? 于是恍然—-缓存了…?? 清空缓存 . 终于可以正常插入数据了. 原来TP在配置文件中如果没有关闭字段缓存设置,默认是开启的,只要一运行它就会将数据字段信息缓存到~Runtime/Data/_files? 文件夹下,并以数组方式存放在文件中.??? protected $fields = array(….); 当然你也可以在模型类里面手动定义数据表字段的名称,可以避免IO加载的效率开销,在模型类里面添加fields属性即可,定义格式如下: ? class UserModel extends Model{ protected $fields = array( ‘id’, ‘username’, ‘email’, ‘age’, ‘_pk’=>’id’, ‘_autoinc’=>true )} 其中_pk 表示主键字段名称 _autoinc 表示主键是否自动增长类型 可以通过设置DB_FIELDS_CACHE 参数来关闭字段自动缓存,如果在开发的时候经常变动数据库的结构,而不希望进行数据表的字段缓存,可以在项目配置文件中增加如下配置: 把这段写在config.php里面 ? ‘DB_FIELDS_CACHE’=>false var ujian_config = { 'num':6, 'showType':2, [...]
原文地址:Thinkphp之字段缓存, 感谢原作者分享。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment