Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pass additional parameters to pagination url

Tags:

yii

Im using CArrayDataProvider for pagination. Now only page numbers are passed in url. I want to pass some more additional attributes. How do I do that? Here is my dataprovider.

$dataProvider = new CArrayDataProvider($arrayData,  array(
                                'keyField'=>'entity_id',
                                'sort'=>array(
                                        'attributes'=>array('entity_id'),
                                        'defaultOrder'=>array('entity_id' => false),
                                ),
                                'pagination'=>array(
                                        'pageSize'=>20,
                                ),
        ));  
like image 327
Palanikumar Avatar asked Dec 08 '22 16:12

Palanikumar


2 Answers

CPagination takes params. Try adding 'params' => array('foo' => 'bar') in pagination.

like image 168
Eirik Hoem Avatar answered Feb 23 '23 12:02

Eirik Hoem


The question was how to pass "additional" parameters.

The code of the accepted answer will override your existing $_GET parameters:

    'params'  => array('foo' => 'bar')

To add "additional" parameters, first add them to existing $_GET parameters:

    $pagerparams = $_GET; 
    $pagerparams['foo'] = 'bar';

    $dataProvider = new CActiveDataProvider($this, array(
        'pagination'=>array(
            'params'  => $pagerparams,
        ),
        ...
    ));
like image 25
Gerhard Liebenberg Avatar answered Feb 23 '23 13:02

Gerhard Liebenberg