model里面:
public function behaviors()
{
return array(
'CTimestampBehavior' => array(
'class' => 'zii.behaviors.CTimestampBehavior',
'createAttribute' => 'create_time',
'updateAttribute' => 'update_time',
)
);
}
[color="#FF0000"]注意我把create_time 和update_time写到rules的required里面[/color]
public function rules()
{
return array(
array('value, points, create_time, update_time', 'required'),
);
}
这个时候,如果是一条新记录
$test = new Test;
$test->value = 0;
$test->points = 0;
如果是用下面的语句,application.log也没有说有错误,输出为 false
echo $test->save();
但如果是直接insert()的话, 就输出为true
echo $test->insert();
如果把create_time,update_time从rules()中去掉,就save()和insert()都没有问题。
是bug来的吗?还是我哪里没有设置好呢?
补充一下,就是[color="#FF0000"]model我是用yiic生成的[/color],就是说,create_time和update_time,required,是生成出来的,如果要用上CTimestampBehavior就会出现这样的bug,要手工把生成的create_time和update_time去掉