[solved] how filter cgridview with join table and some condition and paging

last school?

just use CDbCriteria in controller or in public function model(if needed)




$criteria=new CDbCriteria;

$criteria->order = "school_id DESC";

$criteria->limit = "0,1";

$lastschool=school::model()->find($criteria);


//print out $lastschool['some_column']



To suggest a way without using mergeWith method in the search function in the model when you have a condition to satisfy, you may add $criteria->condition statement before the $criteria->compare statements. In my case, following are the codes:




	public function search()

	{

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

		// should not be searched.


		$criteria=new CDbCriteria;


                //this line should be placed before the $criteria->compare statements

                $criteria->condition='user_idx='.$_GET['id'];

                

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

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

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

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

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

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

                

//                if($merge!==null) //add this line

//                        $criteria->mergeWith($merge);

                

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

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

                


		return new CActiveDataProvider(get_class($this), array(

			'criteria'=>$criteria,

		));

	}