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

Hi,

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(

	'action'=>Yii::app()->createUrl($this->route),

	'method'=>'get',

)); ?>

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


	<div class="row buttons">

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

	</div>




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


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



add this view as partial in "admin",


div class="search-form" >

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

	'model'=>$filtro,

)); ?>

</div>

Add the corresponding in the controller,


	public function actionAdmin()

	{

		$filtro = new FiltroCuotasForm;

		

		$model=new Cuota('search');

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

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

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

		

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

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

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

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

			 								//  FiltroCuotasForm[   flag_solo_impagas]

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

			'model'=>$model,

			'filtro'=>$filtro,

		));

	}

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(

	'id'=>'cuotas-grid',

	'dataProvider'=>$model->search(),

        ....



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->compare('id',$this->id);


		//$criteria->compare('socio_id',$this->socio_id);

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

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

		

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

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

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

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


		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(

		'criteria'=>$criteria,

		'sort'=>$sort,

		'pagination'=>false,

		));

		

		return new CActiveDataProvider($this, array(

			'criteria'=>$criteria,

		));

	}

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