yii1.1model属性动态添加

来源:互联网 发布:手机流量开关软件 编辑:程序博客网 时间:2024/05/18 02:17

 yii中,在model中定义的属性,如果在表中没有这个字段,使用$model->attributes则不能获得那个属性的值。

如何解决呢?在新的model模型中,重写getAttributes方法,

public function getAttributes($names=true){

$arr=parent::getAttributes();
$arr['titles']=$this->titles;
return $arr;
}
0 0
原创粉丝点击