在CakePHP 2中我使用的分页效果很好,直到我看到URL为页面:2,我该如何制作?page = 2?
接下来的问题是我将此代码用于我的控制器,该控制器支持/domain.com/offers/top,/domain.com/offers/newest,/domain.com/offers/popular,然后是/ domain等类别.COM /报价/电视和视频。问题在于/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')
));
答案 0 :(得分:0)