CArrayDataProvider avec CGridView pagination Yii

Je suis en train de faire une pagination sur un CGridView à l'aide de CArrayDataProvider (mon $rawData est un tableau personnalisé - pas à partir d'un DB/modèle).
Ainsi, Dans le contrôleur de l'action sont les suivantes:

$form = new SearchUser;//here I have SearchUser form that extends CFormModel with the following attributes: 'id', 'name', 'surname', 'phone', 'address'
$users = array();
if (isset($_POST['SearchUser'])) {
....//prepare users array from my custom source-> not from DB/models etc
}

$dataProvider=new CArrayDataProvider($users, array(
            'id'=>'id',
            'keys'=>array('name', 'surname', 'phone', 'address'),
            'sort'=>array(
                'attributes'=>array(
                    'name', 'surname', 'phone', 'address'
                ),
            ),
            'pagination'=>array(
                'pageSize'=>15,
            ),
        ));

Et:

$this->render('index', array('dataProvider'=>$dataProvider, 'form'=>$form));

Sur index.php j'ai:

...
<?php echo CHtml::link('Search','#',array('class'=>'search-button')); ?>
<div class="search-form" style="display:none">
<?php $this->renderPartial('_search',array(
'model'=>$form,
)); ?>
</div><!-- search-form -->
<?php

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

    array(
        'name' => 'Name',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["name"])'
    ),
    array(
        'name' => 'Surname',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["surname"])'
    ),/*
    array(
        'name' => 'Phone',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["phone"])'
    ),*/
    array(
        'name' => 'Address',          
        'type' => 'raw',
        'value' => 'CHtml::encode(@$data["address"])'
    ),
),
'enablePagination'=> true,
));

La première page s'affiche correctement mais lorsque je sélectionne une autre page, mon filtre est perdu et toutes les données sont affichées dans la grille au lieu de "filtré" ceux.

  • Dans votre url vous avez ?page=...?
  • J'ai quelque chose comme ceci: &id_page=2
InformationsquelleAutor Larry | 2013-04-18