Yii2 ActiveRecord 添加额外属性

来源:互联网 发布:复杂网络的研究现状 编辑:程序博客网 时间:2024/06/06 13:06

如果你的Form表单中的属性有部分不是在数据库中,而你的Mode又集成了ActiveRecord,这时想通过$model->load()加载那部分未在数据库定义的属性可以重写attributes()函数,例如:

/** * * {@inheritDoc} * * @see \common\db\ActiveRecord::attributes() */public function attributes (){$attributes = parent::attributes();$attributes[] = 'sync_take_rate';$attributes[] = 'sync_show_virtual';return $attributes;}

然后在attributeLabels()和attributeHints()中就和写其他属性设置label、hint一样了。

以上就介绍了Yii2 ActiveRecord 添加额外属性,包括了方面的内容,希望对PHP教程有兴趣的朋友有所帮助。

原创粉丝点击