[Newbie] Problem With Cgridview And Pagination

Hi everybody!

First of all, I don’t know if this is the right forum to leave this comment, but I haven’t found any better one. Please tell me if I’m wrong.

I’ve been working for some years with .net, asp… and I’ve done just a few things in native php. I’m a complete newbie in the world of php-frameworks and MVC, so I have questions that may be silly for you :)

I’m working in a search engine that works this way:

In my main page, I have 2 dropDownLists in a CActiveForm:

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







<div id="buscador">

        <label for="Actividades_Actividad" class="required">Selecciona tu actividad</label>

        <?php echo $form->dropDownList(Actividades::model(), 'IdActividad', CHtml::listData(Actividades::model()->findAll(), 'IdActividad', 'Actividad'), array('options'=>array('42'=>array('selected'=>true)),'name'=>'actividad')); ?>

        <br />

        <br />

        <label for="Municipios_Municipio" class="required">Selecciona tu Municipio</label>

        <?php echo $form->dropDownList(Municipios::model(),     'IdMunicipio', CHtml::listData(Municipios::model()->findAll(" IdIsla = 1 "), 'IdMunicipio', 'Municipio'), array('options'=>array('24'=>array('selected'=>true)),'name'=>'municipio')); ?>       

        <br />

        <br />


        $this->widget('ext.EChosen.EChosen', array('target' => 'select', 'useJQuery' => true, 'debug' => true,)); 

        $this->widget('bootstrap.widgets.TbButton', array('buttonType'=>'submit','type'=>'info','label'=>'Encontrar','loadingText'=>'Buscando...','htmlOptions'=>array('id'=>'buttonStateful','style'=>'margin-left:132px')));?>





Using CActiveForm’s action property, I send the search params to my action “buscar” in my “actividades” controller:

        public function actionBuscar()


                if(isset($_POST['municipio']) and isset($_POST['actividad'])) {

                        $dataProvider=new CActiveDataProvider('Vwactividades', array(


                                        'condition'=>'IdMunicipio = '.$_POST["municipio"].' AND IdActividad = '.$_POST["actividad"]








I get the POST values, perform a search on a db view, and render the view "buscar":


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















                        'value'=>array(Dias::model(), 'getDias')        







                        'value'=>array(Clientes::model(), 'getValoracion')              





The problem is when I try to order the grid by clicking the headers. I receive this alert:

Error 500: <h1>PHP Error [8]</h1> <p>Undefined variable: dataProvider</p>

I understand the problem is when pagination recalls "buscar" action:


and of course… as $_POST is empty, can’t re-create $dataProvider.

I’ve fixed it temporarily making the search params being sent by GET, but I don’t like it. I would prefer the URL to keep as:


…instead of…


Can somebody help me? Maybe I’m doing it wrong from the beginning ::)

Thanks in advance!

[color="#008000"]NOTE: moved to proper section (General Discussions for Yii 1.1.x instead of Tips, Snippets and Tutorials)[/color]

Hi and welcome to the Yii forum…

As for the right forum on where to post, please read all the forum descriptions… for example the forum where you posted (Tips, Snippets and Tutorials) has this description: "[size="2"]Share your tips, snippets and experiences about Yii, and discuss about best Yii practices.[/size][color=#606060][size=2]"[/size][/color]



[size=2]Maurizio Domba[/size]

Thanks Maurizio!