在Model中的search()函数 public function search() { // @todo Please modify the following code to remove attributes that should not be searched. $criteria=new CDbCriteria; //$criteria->with = array('author'); //添加了和 author 的渴求式加载 // $this->state = "not_passed"; $criteria->compare('state',$this->state); //这里添加了一个 compare, username 是 User 表的字段,$this->name 是我们添加的属性,true 为模糊搜索 //$criteria->compare('username',$this->name,true); return new CActiveDataProvider($this, array( 'criteria'=>$criteria, )); 以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持中文源码网。