开发者

Cakephp pagination problem with next/previous

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') &&am开发者_如何学编程p; !$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...


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.


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜