Problem with "LIMIT" argument in CDbCriteria

I have a game application with a leaderboard that shows the highest scores.

I tried to increase the number of results shown in the leaderboard by changing the value of the "limit" parameter passed

in the CDbCriteria array




                  $high_scores_dp = new CActiveDataProvider('score',

                                    array('criteria' =>

                                        array('condition' => 'game_id = ' . $model->id,

                                              'order' => 'score desc',

                                              'limit' => 20,     //  <=== TRIED CHANGING THIS VALUE

                                             )

                                         )

                                  );



The original value of "limit" was 10, and I changed it to 20.

But after viewing the page, only 10 results were still shown.

I used the CFileLogRoute to view the SQL generated and the the query showed "LIMIT 10" still.

So I’m totally confused why I can’t change the value of the “limit” arg.

Is there some kind of sql query caching going on?

Anyone have ideas?

Another thing I tried was modifying the data so it would return different results (different DB rows returned), but still only 10 rows were returned. I also turned off memcache, but still no difference. I also changed the “order” argument to sort by “ASC” instead of “DESC” to make sure the same query wasn’t always being run. The results changed, but the limit was still 10.

Do you use pagination? I guess, it will override LIMIT with the configured pageSize.

Hey Mike, thanks for your comment.

I wasn’t explicitly using or not using pagination. But your comment led me to add the line below and now things are working. (This seems like a bad default behavior for Yii).




                  $high_scores_dp = new CActiveDataProvider('score',

                                    array('criteria' =>

                                        array('condition' => 'game_id = ' . $model->id,

                                              'order' => 'score desc',

                                              'limit' => 20,

                                             ),

                                   'pagination' => false            // <=== FIXED BY ADDING THIS LINE


                                         )

                                  );



Yii follows the “convention over configuration” paradigm. CActiveDataProvider was actually introduced to make working with sorting/pagination/filtering quick and painless. That’s why by default this component has some sane default settings.