Cactivedataprovider Problem Pagination With Criteria "with"

Hi everybody,

I’m facing a strange behavior with CListView when my CActiveData include à with criteria the pagination isn’t working anymore, I can change the page but the data doesn’t change ??.




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

                'with' => array('somethingElse'),

)); // PAGINATION DOESN'T WORK


$dataProvider = new CActiveDataProvider('Something'); // WITH NOTHING

)); // PAGINATION WORK


/*  WHY <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/huh.gif' class='bbc_emoticon' alt='???' /> */







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

        'dataProvider'=>$dataProvider,

        'itemView'=>'_view',

)); ?>




Thanks

Try this


new CActiveDataProvider('Something', array(

    'criteria' => array(

        'with' => array('somethingElse'),

    )

)

Here’s an example from docs


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

    'criteria'=>array(

        'condition'=>'status=1',

        'order'=>'create_time DESC',

        'with'=>array('author'),

    ),

    'countCriteria'=>array(

        'condition'=>'status=1',

        // 'order' and 'with' clauses have no meaning for the count query

    ),

    'pagination'=>array(

        'pageSize'=>20,

    ),

));

// $dataProvider->getData() will return a list of Post objects

Still not working

When you say it’s not working, what exactly happens?

Is the behaviour similar to this one?

Nope, the pagination doesn’t work.

Example

id

1

2

3

page 1

if I click next page the data will be :

id

1

2

3

page 2

instead of

id

4

5

6

page 2

???

Thanks for help

I am taking a wild guess here:

If the relationship between Something and SomethingElse is one-to-many (i.e. one Something has many SomethingElse), is it possible that ‘SomethingElse’ is leading to the repetition of data from the Something model?

If that isn’t the problem, then post the ‘_view.php’ code, the relations part of both the Something and SomethingElse models and the code for the function in which you are defining the DataProvider.

I think BlkRaven is right, that happens with a one-to-many with in gridview. The problem is that it runs a count before pagination, gets a total that includes the with’d results, and gets a total number of posts that are more than you have. If you’re using together=>true, you could set it to false.