duanji1056 2014-05-18 20:34
浏览 86
已采纳

Yii afterfind没有开火

I am not sure why my yii afterFind method is not firing. Below is what i used to test the yii afterfind method. For every find, the first_name should be "hahahahahaa". This is just to test that the afterfind is working

Below is my model class of user:

class User extends CActiveRecord
{
 public function getUserInfo($userid,$is_all=false){
         $criteria = new CDbCriteria;
         $criteria->select = 'id,email,first_name,last_name,gender,username,country,balance_bids';
         if($is_all ){
             $criteria->select = 'id,email,first_name,last_name,gender,username,country,'
                 . 'dob,address1,address2,zip,balance_bids,mobile';
         }
         $criteria->condition = "id=:userid";
         $criteria->params = array(':userid'=>$userid); 

         return User::model()->find($criteria);
 }

 protected function  afterFind(){
      $this->first_name = "hahahaha";
      parent::afterFind();

 }

}

However when I call the getUserInfo () method from the controller, the afterfind method isn't firing at all. The first_name isn't "hahahahaha".

  • 写回答

1条回答 默认 最新

  • doufeng3602 2014-05-18 21:08
    关注

    how about

     User::model()->find($criteria);
    

    because you declared static function, and usage of $this is not recommended

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部