如果你的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教程有兴趣的朋友有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号