【问题标题】:CakePHP Pagination Routing IssuesCakePHP 分页路由问题
【发布时间】:2014-02-02 22:46:44
【问题描述】:

在 CakePHP 2 中,我使用的分页效果很好,直到我看到 URL 为 page:2,我该如何制作?page=2?

下一个问题是我将此代码用于我的控制器,它为 /domain.com/offers/top、/domain.com/offers/newest、/domain.com/offers/popular 和 /domain 等类别提供动力.com/offers/tv-and-video。问题是当它为 /domain.com/offers/top 而不是 /offers/top/page:2 分页时,它转到 /offers/bycategory/top/page:2。

 public function bycategory($slug = null)
{

    $userId = $this->Session->read("UserAuth.User.id");
    if ($slug == 'top') {
        //Get the top rated offers
        $this->paginate = array(
            'limit' => 15,
            'order' => array(
                'Offer.vote' => 'desc'
            )
        );
    } elseif ($slug == 'newest') {
        //Get the latest offers
        $this->paginate = array(

            'limit' => 15,
            'order' => array(
                'Offer.created' => 'desc'
            )
        );
    } elseif ($slug == 'popular') {
        //Get the most talked about offers
    } else {

        //This is the categories, so just get the category slug.
        $this->paginate = array(
            'conditions' => array('Category.slug =' => $slug),
            'limit' => 15,
            'order' => array(
                'Offer.created' => 'desc'
            )
        );


    }


    $offers = $this->paginate('Offer');

    // pass the value to our view.ctp
    $this->set('offers', $offers);
    $this->set('userId', $userId);

    $this->render('/Offers/index');


}

这是我的自定义路线:

Router::connect(
'/offers/:catslug',
array('controller' => 'offers', 'action' => 'bycategory'),
array(

    'pass' => array('catslug')

));

【问题讨论】:

  • 不要使用 cakephp 分页来实现这些目标。

标签: php cakephp pagination cakephp-2.3


【解决方案1】:

我怎样才能做到这一点?page=2?

通过在manual 中提到的分页器组件选项中设置paramType 选项。

您的第二个问题看起来像反向路由问题。您是否设置了任何自定义路线?

【讨论】:

  • 我刚刚添加了我的自定义路线。
  • 您必须使用PaginatorHelper:options() 为其生成的url 设置catslug 路由参数,或者在Route::connect() 语句中使用persist 选项,以便catslug 在url 中持续存在时反向路由。
猜你喜欢
  • 1970-01-01
  • 2012-06-27
  • 2011-05-25
  • 2012-09-26
  • 1970-01-01
  • 1970-01-01
  • 2012-03-03
  • 2012-11-28
相关资源
最近更新 更多