在创建的时候 created_at 与 updated_at都需要更新,更新的时候只更新 updated_at 此时可以定义行为,字段类型设置为int型的时间戳,参考如下:
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
public function behaviors()
{
return [
[
‘class’ => TimestampBehavior::class,
‘createdAtAttribute’ => ‘created_at’,
‘updatedAtAttribute’ => ‘updated_at’,
‘attributes’ => [
ActiveRecord::EVENT_BEFORE_INSERT => [‘created_at’, ‘updated_at’],
ActiveRecord::EVENT_BEFORE_UPDATE => [‘updated_at’],
],
// 设置默认值
‘value’ => time(),
],
];
}
微信公众号
手机浏览(小程序)
Warning: get_headers(): SSL operation failed with code 1. OpenSSL Error messages:
error:14090086:SSL routines:ssl3_get_server_certificate:certificate verify failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(): Failed to enable crypto in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57
Warning: get_headers(https://static.shanhubei.com/qrcode/qrcode_viewid_2359.jpg): failed to open stream: operation failed in
/mydata/web/wwwshanhubei/web/wp-content/themes/shanhuke/single.php on line
57