如何使用model中的search?

我需要对多张表进行匹配搜索,在model中的search方法中这样写对吗?




public function search()

{

	// Warning: Please modify the following code to remove attributes that

	// should not be searched.

	$criteria=new CDbCriteria;

	$criteria->order = 'uid desc';

	$criteria->compare('shopid',$this->shopid);

	$criteria->compare('uid',$this->uid);

	$criteria->compare('beizhu',$this->beizhu,true);

	$criteria->compare('bzszm',$this->bzszm,true);

	$criteria->compare('quan',$this->quan);

	$criteria->compare('entry_time',$this->entry_time);

	$criteria->compare('status',$this->status);


	$criteria->with = array('UserBaseInfo');

	$criteria->compare('UserBaseInfo.sex', 'm');


	return new CActiveDataProvider($this, array(

		'criteria'=>$criteria,

		'pagination'=>array(

			'pageSize' => 2

		)

	));

}



这样写了之后返回的CActiveDataProvider对象又该如何操作呢??

小弟才学YII,如果有其他的方法谢谢指出。 ???

这里有一个wiki 你可要参考:Searching and sorting by related model in CGridView

需要你做的是 在主ar中新建公共变量 并在rules中将其添加到search场景中 代码参考wiki所给 :lol:

谢谢你!