我有一个带有price
列的表单,mysql类型为Decimal,可以为null。我的模型设置如下:
use yii\behaviors\AttributeTypecastBehavior;
class Item extends \yii\db\ActiveRecord
{
public function rules()
{
return [
['amount', 'integer'],
['price', 'number'],
['is_active', 'boolean'],
];
}
public function behaviors()
{
return [
'typecast' => [
'class' => AttributeTypecastBehavior::className(),
],
];
}
public function afterSave($insert,$changedAttributes)
{
parent::afterSave($insert,$changedAttributes);
print_r($changedAttributes); // shows the number attributes as being changed when they have not actually changed
// ...
}
如何设置我的模型,以便在price
中afterSave()
属性确实发生了变化?它似乎与amount
(整数)属性一起使用。