0

Let's say I have this page with pagination:

localhost/fr/users/index/page:1

I see the correct results for page 1 based on how I have defined the paginate var in my controller. But when I click the next button, the url change to page:2 but the results don't change and are the same as page:1, same thing for page:3, page:4 and so on...

If I first sort a column, let's say username, then I can use the previous/next link without any problem, the data change on each page.

The only thing I can think of that could cause me problem is that I use a language param in my urls but I have no idea how to fix this...

I'm currently using Cake 1.2.5. I also tried with 1.3 beta with same results.

Ok so here's my Users controller code:

var $paginate = array('limit'=>'5');
function index() {
$this->User->recursive = 0;
$this->set('users', $this->paginate());
}

I'm using teknoid tutorial for language switching:

URL-based language switching...

language param added through app_helper.php

function url($url = null, $full = false) {
    if(!isset($url['language']) && isset($this->params['language'])) {
        $url['language'] = $this->params['language'];
     }     

     return parent::url($url, $full);
}

and language switching done using a method in the app_controller.php:

function _setLanguage() {

    if ($this->Cookie->read('lang') && !$this->Session->check('Config.language')) {
        $this->Session->write('Config.language', $this->Cookie->read('lang'));
    }
    else if (isset($this->params['language']) && ($this->params['language']
         !=  $this->Session->read('Config.language'))) {     

        $this->Session->write('Config.language', $this->params['language']);
        $this->Cookie->write('lang', $this->params['language'], null, '20 days');
    }
}

SOLUTION:

After setting up yahoo boss site and noticing that paging was working flawlessly, I looked more closely at my code and found the problem was inside my routes.php.

I had this:

Router::connect('/news', array('controller'=>'news', 'action'=>'index'));

Router::connect('/:language/news', array('controller'=>'news', 'action'=>'index'), array('language'=>'[a-z]{2}'));

I modified it like this to take all the params:

Router::connect('/news/*', etc...

Router::connect('/:language/news/*', etc...
1
  • Some code would help, particularly the UsersController::index() action, and perhaps some details on how you're doing the language param.
    – deceze
    Feb 4, 2010 at 1:47

2 Answers 2

0

Show us the controller code, the view code and some example urls. I've had similar problems in the past, but nobody can help if you don't give us more info.

0
0
Even i faced the similar problem

**Solution**

I closely checked all my code and after trial and errors i was able to find the solution

First the cause: I was doing a order by 
$this->paginate = array(
            'limit' => 20,
            'order' => array('Test.aws_id' => 'asc'),
            'conditions' => $condition_options
        );

The above code was returning first page result across all pages.

After a while i closely checked everything and the result set.
The resultset was returning me **capital AWS_ID** and i was doing my ordering on aws_id after changing it to caps my code was working

Hope this helps someone

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.