`
niqingyang
  • 浏览: 42599 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Yii2 ActiveRecord 添加额外属性

    博客分类:
  • YII
阅读更多

如果你的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一样了。

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics