HOWTO : In admin or index view, add a functional filter criteria


I want to add a functional filter criteria to the admin or index view.

The idea is to provide the user a simple combo, with diferent options to filter the data.

The combo will be translated to search criterias …

What I did, and didn’t work, is:

create a model "FiltroCuotasForm" :

class FiltroCuotasForm extends CFormModel


	public $flag_solo_impagas;


	 * Declares the validation rules.


	public function rules()


		return array(




	 * Declares customized attribute labels.

	 * If not declared here, an attribute would have a label that is

	 * the same as its name with the first letter in upper case.


	public function attributeLabels()


		return array(

			'flag_solo_impagas' => 'Que cuota desea ver ?',

			//'verifyCode'=>'Verification Code',





Create a view: "_filtro"

div class="wide form">

<?php $form=$this->beginWidget('CActiveForm', array(



)); ?>

	<div class="row">

		<?php echo $form->label($model,'flag_solo_impagas'); ?>

		<?php echo $form->dropDownList($model,'flag_solo_impagas',array('T'=>'Todas','P'=>'Solo pagas', 'I'=>'Solo Impagas')); ?>


	<div class="row buttons">

		<?php echo CHtml::submitButton('Filtrar'); ?>


<?php $this->endWidget(); ?>

</div><!-- search-form -->

add this view as partial in "admin",

div class="search-form" >

<?php $this->renderPartial('_filtro',array(


)); ?>


Add the corresponding in the controller,

	public function actionAdmin()


		$filtro = new FiltroCuotasForm;


		$model=new Cuota('search');

		$model->unsetAttributes();  // clear any default values




		//Yii::Log("Filtro Cuota : ". var_dump($filtro));	

		Yii::Log("Filtro Cuota : ". $_GET['FiltroCuotasForm']);


			$filtro->flag_solo_impagas = $_GET['FiltroCuotasForm']['flag_solo_impagas'];

			 								//  FiltroCuotasForm[   flag_solo_impagas]






ok, the problem is that variable $_GET[‘FiltroCuotasForm’] is null or empty allways.

Also, in "admin" view the data provider for CGridView is:

$this->widget('zii.widgets.grid.CGridView', array(




And the model got this search method:


	 * Retrieves a list of models based on the current search/filter conditions.

	 * @return CActiveDataProvider the data provider that can return the models based on the search/filter conditions.


	public function search($filtro=null)


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

		// should not be searched.

		$criteria=new CDbCriteria;



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

		$criteria->addSearchCondition('socio.apellidoynombre', $this->socio_id);






		if (isset($filtro) && $filtro = 'I')

		  $criteria->addCondition('imp_pagado < per_importe');

		if (isset($filtro) && $filtro = 'P')

		  $criteria->addCondition('imp_pagado >= per_importe');



		$_SESSION['datos_filtrados'] = new CActiveDataProvider($this, array(






		return new CActiveDataProvider($this, array(




My idea is that, in "admin" view, call search method with a parameter, and there create the correct searchCriteria.

Can anybody tell me what I’m doing wrong ??

Best Regards