时间戳行为不起作用
Timestamp behavior not working
我有一个字段start_date,它将在保存数据(未更新)时采用当前时间戳。像这样的行为:
$this->addBehavior('Timestamp', [
'events' => [
'Model.beforeSave' => [
'start_date' => 'new'
]
]
]);
但我认为没有填充当前时间戳,因为我收到此错误:
'start_date' => [
(int) 0 => 'This field is required'
]
您已订阅 Model.beforeSave
事件,因此在保存之前会立即生成时间戳,即 在 验证和规则检查之后,因此会出现错误。
如果您出于任何原因需要验证此字段(通常不需要),请订阅 Mode.beforeRules
event and use the rules checker 以验证该字段。
因为您确信 start_date
是由附加行为提供的,所以从验证规则中删除该字段。至少我就是这么做的。
我有一个字段start_date,它将在保存数据(未更新)时采用当前时间戳。像这样的行为:
$this->addBehavior('Timestamp', [
'events' => [
'Model.beforeSave' => [
'start_date' => 'new'
]
]
]);
但我认为没有填充当前时间戳,因为我收到此错误:
'start_date' => [
(int) 0 => 'This field is required'
]
您已订阅 Model.beforeSave
事件,因此在保存之前会立即生成时间戳,即 在 验证和规则检查之后,因此会出现错误。
如果您出于任何原因需要验证此字段(通常不需要),请订阅 Mode.beforeRules
event and use the rules checker 以验证该字段。
因为您确信 start_date
是由附加行为提供的,所以从验证规则中删除该字段。至少我就是这么做的。