How to override empty value of CActiveRecord attribute?

My CActiveRecord Class is User.class.php,I wannt to give a default avatar for records,how Can I do that?

Here’s my code,When I call $user->headimgurl in view, it didnt work.Please help me!Or I must to add another function like getAvatar()?




<?php

/**

 * @property string $id

 * @property string $headimgurl

 * ..................

*/

class Wxuser extends CActiveRecord{


        //........


	public function getAttribute($name) {

	    if(($name === 'headimgurl') && empty(parent::getAttribute($name))){

		return '/images/defaultheadimg.jpg';

	    }

	    return parent::getAttribute($name);

	}




}



Exactly, you can add




public function getHeadimgurl()

{

....

}



to call $user->headimgurl;

hi

in model :




public function getHeadimgurl(){

if(($this->name === 'headimgurl') && empty($this->name)){

                return '/images/defaultheadimg.jpg';

            }

            return $this->name;


}






getAvatar()



is a good idea just add a new method