Home  >  Article  >  PHP Framework  >  Regarding the adjustments to the time field in the latest version of ThinkORM

Regarding the adjustments to the time field in the latest version of ThinkORM

藏色散人
藏色散人forward
2021-04-16 09:43:022200browse

The following tutorial column of thinkphp will introduce to you the adjustments to the time field in the latest version of ThinkORM. I hope it will be helpful to friends in need!

Regarding the adjustments to the time field in the latest version of ThinkORM

Many users have been unable to obtain the original value of the time field after upgrading to the latest version of the 6.0 framework. This is due to a latest adjustment in the think-orm library. .

In the latest ThinkORM, the automatic processing of field types and time fields is no longer included in the scope of the getter. Instead, it is processed as soon as the results are queried to avoid the need for data to be called every time in the future. Additional testing and processing are required every time. Since the getter is no longer included, the original values ​​of these fields cannot be obtained, including fields with type conversion set and automatic time processing fields.

The automatic processing of time fields is a function provided by the framework to implement automatic writing and automatic output conversion of time fields (including create_time and update_time, which supports custom field names).

If you need to get the original value of the time field, you need to turn off the automatic time field processing function, that is, set the autoWriteTimestamp attribute to false, and then customize the time field getter to take over the output of the time field, and remember that once Turn off automatic time field processing, and data writing for time fields must be written manually.

If you want the time field to be automatically written and processed, but do not want to automatically format the output, you can set the dateFormat attribute to false. If set in the database configuration file, it should be set as follows:

// 自动写入时间戳字段
// true为自动识别类型 false关闭
// 字符串则明确指定时间字段类型 支持 int timestamp datetime date
'auto_timestamp'  => true,
 
// 时间字段取出后的默认时间格式
'datetime_format' => false,

Upgrading to the latest version of think-orm has corrected the above problem, but note that it is best to use the getOrigin method instead of the getData method to obtain the original data, if you need To read the original time field data in the defined getter method, you should use $this->origin['create_time'] instead of $data['create_time'] or $this->data['create_time'] .

Related recommendations: The latest 10 thinkphp video tutorials

The above is the detailed content of Regarding the adjustments to the time field in the latest version of ThinkORM. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:thinkphp. If there is any infringement, please contact admin@php.cn delete