Yii2 - $ changedAttributes for number(类型转换?)

时间:2017-02-06 07:20:07

标签: mysql activerecord yii2 typecasting-operator

我有一个带有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

    // ...
}

如何设置我的模型,以便在priceafterSave()属性确实发生了变化?它似乎与amount(整数)属性一起使用。

0 个答案:

没有答案