Cactivedataprovider Not Switching Pages

CActiveDataProvider is being used to create a paginated list of results from a search form I made.

First page works properly but if I click on page 2 for example, it clears the CActiveDataProvider instead of switching results. Can anyone tell me what is happening.




function actionSearch() {

   if (!empty($_POST['id'])) {

       $searchResults = $this->search($_POST);

   }

   // render to view with $searchResults

}


function search($postData) {

   // Search using the $postData in $criteria


   // Creates a 5 page pagination CActiveDataProvider using the $criteria


   return $dataProvider;

}



Sorry for the minimal code I am trying to simply what to look at this is the basic algoritm for the search method and how it builds the CActiveDataProvider.

Since I built a basic pagination in a sandbox app for testing I didn’t pass variables in a POST form, so that worked as expected, but now that I have used it in a search where I pass variables in POST I am not sure how to get past this issue. Thanks in advance for the help.

You should show us how do you configure the pagination in the dataProvider.




            $dataProvider = new CActiveDataProvider($modelName, array(

                'criteria'=>$criteria,

                'pagination'=>array(

                    'pageSize'=>5,

                ),

            ));






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

            'dataProvider'=> $dataProvider,

            'id' => 'results-list-view',

            'itemView'=>'_results',

            'pagerCssClass' => false,

            'pager' => array(

                'cssFile' => '/css/styles.css',

                'header' => false,

                'prevPageLabel' => 'Prev',

                'nextPageLabel' => 'Next',

            ),

        ));



Here is an isolated code that does the same exact thing my site is doing…

(Controller) Index action and search function




	public function actionIndex()

	{

        $dummyDataProvider = null;

        if (!empty($_POST['title'])) {

            $postData = $_POST;

            $dummyDataProvider = $this->search($postData);

        }

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

            'dummyDataProvider' => $dummyDataProvider,

        ));

	}


    public function search($data=null) {

        $model = Dummy::model();

        $criteria = new CDbCriteria();

        $criteria->order = 'id ASC';

        $criteria->condition = 'title LIKE \'%' . $data['title'] . '%\'';

        return new CActiveDataProvider($model, array(

            'criteria'=>$criteria,

            'pagination'=>array(

                'pageSize'=>1,

            ),

        ));

    }



(View)




<?php echo CHtml::beginForm(); ?>

<?php echo CHtml::textField('title', '', array('class' => 'span8', 'placeholder' => 'enter letter')); ?>

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

<?php echo CHtml::endForm(); ?><?php

    if ($dummyDataProvider) {

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

            'dataProvider'=> $dummyDataProvider,

            'id' => 'dummy-list-view',

            'itemView'=>'_dummyList',

            'template' => '

                            <div class="span9 pull-right">

                                <div class="pagination pagination-right">

                                    {pager}

                                </div>

                           </div>

                            <div style="border-bottom:1px solid #000;overflow:hidden;margin-bottom:5px;">

                                <div style="float:left;width:100px;text-align:center;">ID:</div>

                                <div style="float:left;width:100px;text-align:center;">Title:</div>

                                <div style="float:left;width:100px;text-align:center;">Action:</div>

                            </div>

                           {items}',

            //'cssFile' => falses,

            'pager' => array(

                'header' => false,

                //'cssFile' => false,

                'prevPageLabel' => 'Prev',

                'nextPageLabel' => 'Next',

            ),

            'sortableAttributes'=> array (

                'id'=>'ID',

                'title' => 'Title',

                'action' => 'Action',

            ),

        ));

    }

?>



Hi wicked357,

Use get method.

CListView handles pagination and sorting by get method.

http://www.yiiframework.com/wiki/381/cgridview-clistview-and-cactivedataprovider

I got it to work by setting this…

$dummyDataProvider->getPagination()->params = array(“title” => $post[‘title’], ‘test’ => ‘test’);

then as mentioned by softark using $_GET if $_POST isn’t populated in my action.

Problem: In my example version it does it without posting those attributes to the url, in my website it is posting all of them in the url but it works. I would prefer the cleaner look.

Any ideas what would cause this?