function search() in model extending CFormModel

Greetings!!

I have a big doubt and i would like to resolve this.

I created manually a model that extends CFormModel with the name "Routing". Basically this model just merge two tables from database. My ROUTINGController has a function actionAdmin():


public function actionAdmin()

	{

		$model=new routing('routing');

		$model->unsetAttributes();

		if(isset($_GET['routing'])) 

			$model->attributes=$_GET['routing'];

		

		$rawData=Yii::app()->db->createCommand('SELECT * FROM routing_rule INNER JOIN routing_destination ON routing_rule.serviceid=routing_destination.serviceid')->queryAll();


		$dataProvider=new CArrayDataProvider($rawData, array(

			'keyField'=>'SERVICEID',

			'sort'=>array(

				'attributes'=>array('SERVICEID'),),

			'pagination'=>array('pageSize'=>20),

		));

		$this->render('admin', array(

			'model' => $model,

			'dataProvider' => $dataProvider,

		));

	}

My admin view uses CGridView to show the results with the options to manipulate the data (view, update, delete, advanced view).

What i am looking for is to use the AdvancedView. Since im using CFormModel and CArrayDataProvider i can’t use the CDbCriteria to filter the results. I cant even understand how the framework saves the filters we want for search.

What i really would like is to have a function in my "Routing" model public function search() like the gii when generates the model from DB (extending CActiveRecord in spite of CFormModel).

I apreciate any help :) thank you

Hi,

What is the relation between "routing_rule" and "routing_destination"? BELONGS_TO or HAS_MANY?

Anyway, I think you should use CActiveRecord if those 2 tables have some relation.

Hi softark! Thank you for your time.

"Routing" is not a table in DB, so i cant extend from CActiveRecord. By the name, "Rule" means a rule for a purpose information, the "destination" is the destination for that rule. So, if a rule exists, it means a destination has to exist also.

Still looking for solution ;/

Did you read "Relational Active Record" section of the guide?

http://www.yiiframework.com/doc/guide/1.1/en/database.arr

If yes, could there be any reason for you to avoid using Relational AR?

Im reading right now. I believe this should solve the problem :)

Thank you softark. Once i get news ill reply

And don’t forget to check this wiki. :)

http://www.yiiframework.com/wiki/281/searching-and-sorting-by-related-model-in-cgridview

sweet!! This resolved my problem hehe,

I really apreciate your help softark. Big big thanks! :P