ExampleModel.php
/**
* {@inheritdoc}
*/
public function rules()
{
return [
['updated_at','default','value'=>time(),'on'=>[self::SCENARIO_ADD],'skipOnEmpty'=>false],
['updated_at','editUpdatedAt',on'=>[self::SCENARIO_ADD],'skipOnEmpty'=>false],
];
}
public function editUpdatedAt($attribute, $params) {
$this->updated_at = time();
}
- 设置为
default
时,当编辑的时候,update_at有值的时候就不会更新成time(),应该写新方法editUpdatedAt更新updated_at值 - skipOnEmpty 默认为true,当检测项为空自动跳过,如果为空仍检测的应设置为false