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);
}
}