yii2.0行為:資料型別轉換
阿新 • • 發佈:2019-02-13
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(), // 'attributeTypes' will be composed automatically according to `rules()` ], ]; } // ... }