ActiveDropdownList

I have two ActiveDropdownList for get the result of the intersection of them

for example i wont to get from the category autos, all the cars from the category Mercedes.

De problem is when i click the second option it actualice only by checking the second parameter.

this is my view.php




<?php

Yii::app()->clientScript->registerScript('index',

    "var ajaxUpdateTimeout;

    var ajaxRequest;

   	$('.categoryFilter').change(function(){

    categoria_id = $('.categoryFilter').serialize();

	marca_id = $('.marcaFilter').serialize();

	marca_id = $('.marcaFilter').serialize();

    $.fn.yiiListView.update(

     	'ajaxListView',

                {

					 url: '" . CController::createUrl('Post/index') . "',

				   data: categoria_id

                }

    );

});

	$('.marcaFilter').change(function(){

    marca_id = $('.marcaFilter').serialize();

	categoria_id = $('.categoryFilter').serialize();

    $.fn.yiiListView.update(

     	'ajaxListView',

                {

				   url: '" . CController::createUrl('Post/index') . "',

				   data: marca_id,

				 

				   

                }

    );

});

	"

);


echo CHtml::activeCheckboxList(

  $model, 'categoria_id', 

  CHtml::listData(Categoria::model()->findAll(), 'id', 'name'),

  array('template'=>'<li>{input} {label}</li>',  'class'=>'categoryFilter',)

  

);

echo CHtml::activeCheckboxList(

  $model, 'marca_id', 

  CHtml::listData(Marca::model()->findAll(), 'id', 'name'),

  array('template'=>'<li>{input} {label}</li>',  'class'=>'marcaFilter',)

);


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

	'id'=>'ajaxListView',

    'dataProvider'=>$dataProvider,

    'itemView'=>'_view',

	//'filter'=>$model->search(),

    'sortableAttributes'=>array(

        'id',

		'title',

		'categoria_id'

    ),

	'pager' => array( 

       'prevPageLabel'=>'< Prev',

       'nextPageLabel'=>'Next >',

       'header'=>'Pagina: ',

       'pageSize'=>5,

	),

    

));

?>



this is the controller.php




public function actionIndex( array $categoria_id = array(), array $marca_id = array() )

{

	$categoria_id = (isset($_GET['Post']['categoria_id'])) ? $_GET['Post']['categoria_id'] : array();

	$marca_id = (isset($_GET['Post']['marca_id'])) ? $_GET['Post']['marca_id'] : array();

	CVarDumper::dump($categoria_id);

	$model=new Post();

    $criteria = new CDbCriteria();

    if( count( $categoria_id ) > 0 )

		$criteria->addInCondition( 'categoria_id', $categoria_id );

	if( count( $marca_id ) > 0 )

		$criteria->addInCondition( 'marca_id', $marca_id );

	

	$dataProvider = new CActiveDataProvider( 'Post', array( 'criteria' => $criteria, ) );

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

		'dataProvider' => $dataProvider,

		'model'=>$model, 

	));

}



If you need of the intersection, you must always send the data from marcas and categorias.

Something like this:




Yii::app()->clientScript->registerScript('index', "var ajaxUpdateTimeout;

    var ajaxRequest;

    $('.categoryFilter, .marcaFilter').change(function(){

        categoria_id = $('.categoryFilter').serialize();

        $.fn.yiiListView.update(

            'ajaxListView',

            {

                url: '" . CController::createUrl('Post/index') . "',

                data: $('.categoryFilter, .marcaFilter').serialize();

            }

        );

    });

    "

);



The firebug is a good friend to debug and verify the request being sent in the POST.