function search() in model extending CFormModel


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');





		$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(






		$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


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?

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. :)

sweet!! This resolved my problem hehe,

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