Cakephp 下一个/上一个分页问题

发布于 2024-08-20 07:44:21 字数 2163 浏览 2 评论 0原文

假设我有一个带有分页的页面:

localhost/fr/users/index/page:1

根据我在控制器中定义分页变量的方式,我看到了第 1 页的正确结果。但是当我单击“下一步”按钮时,网址更改为 page:2 但结果不会更改并且与 page:1 相同,page:3、page:4 等相同...

如果我首先对一列进行排序,假设用户名,然后我可以毫无问题地使用上一个/下一个链接,每个页面上的数据都会发生变化。

我能想到的唯一可能导致我出现问题的是我在网址中使用了语言参数,但我不知道如何解决这个问题......

我目前正在使用 Cake 1.2.5。我也尝试过 1.3 beta,结果相同。

好的,这是我的用户控制器代码:

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

我正在使用 teknoid 教程进行语言切换:

基于 URL 的语言切换...

通过 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);
}

,并使用 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');
    }
}

解决方案:

设置 yahoo boss 站点并注意到分页工作完美后,我更仔细地查看了我的代码,发现问题出在我的routes.php 中。

我有这个:

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

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

我像这样修改它以获取所有参数:

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

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

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...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚气少女 2024-08-27 07:44:21

向我们展示控制器代码、视图代码和一些示例 url。我过去也遇到过类似的问题,但如果您不向我们提供更多信息,没有人可以提供帮助。

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.

玉环 2024-08-27 07:44:21
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
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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文