【问题标题】:How to pass pagination parameters with additional params cakephp?如何使用附加参数 cakephp 传递分页参数?
【发布时间】:2013-07-28 23:51:36
【问题描述】:

我有一个类别列表,其中显示了它下面的项目列表。

因此:

路线有:

Router::connect('/category/:slug', array('controller' => 'Product',
             'action'=>'catview', 'slug'=> '[0-9a-zA-Z]+'));
Router::connect('/category/:slug/:page', array('controller' => 'Product',
             'action'=>'catview','slug'=> '[0-9a-zA-Z]+','page'=>'[0-9]+'));

当我在结果页面中执行此操作时,它不起作用:

<?php 
        $slug = $this->params['slug'];
        $this->Paginator->options(array('url'=> array('controller' => 'Product',
                             'action'=>'catview','slug'=> $slug)));

        echo $this->Paginator->prev('<< Show me previous', array('class'=>'prev'))
        . $this->Paginator->next('Show me more >>', array('class'=>'next')); ?>

它不会改变结果,它显示的结果与第 1 页上的结果相同。

任何想法我哪里出错了?

【问题讨论】:

  • 下一个/上一个链接指向什么 url? IME 你最好使用 get params 作为分页变量。
  • 他们显示/:slug/:page,如/Calculators/2
  • /Calculators/2 与问题中的任何一条路线都不匹配。
  • @AD7six 能否请您对“获取分页变量的参数”进行一些说明? PS:我不在乎 URL 看起来是否丑陋。我只需要正确的结果,但是,我需要输入 $this->paginate->options URL,因为我使用的是 slug,否则它会重定向到 /controller/action/:page
  • using get params for pagination 只用您使用的蛋糕版本标记您的问题 - 是 2.0 还是 2.3?

标签: cakephp pagination cakephp-2.3


【解决方案1】:

感谢AD7six 提供参考。

我的控制器需要:

$this->paginate = array(
 //other stuff here
 'paramType' => 'querystring'
);

接着是:

$this->Paginator->options(array('url'=> array('controller' => 'Product',
                                  'action'=>'catview','slug'=> $slug),
                                     'convertKeys' => array('page')));

在视图文件中

【讨论】:

    猜你喜欢
    • 2013-03-11
    • 1970-01-01
    • 2014-08-15
    • 1970-01-01
    • 2013-01-13
    • 2012-04-21
    • 1970-01-01
    • 1970-01-01
    • 2013-06-03
    相关资源
    最近更新 更多