【发布时间】: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