我正在使用CakePHP 3.0对某些内容进行分页,但是我无法使用Paginator
内置方法来改变限制(浏览器上的用户选择屏幕上显示的内容限制) (比如内置排序),要做到这一点,我使用javascript来更改URL中的限制。
Qustion:以cakephp风格存在任何方式吗?
使用分页的控制器操作
public $helpers = [
'Paginator' => ['templates' => 'paginator-templates']
];
public function search()
{
if($this->request->is('get'))
{
$search = $this->request->query['search'];
@$limit = $this->request->query['limit'] ?: 3;
$this->paginate = [
'conditions' => ['product_name LIKE' => '%' . $search . '%'],
'limit' => $limit,
'contain' => ['Medias' => function($q){
return $q->select(['path', 'product_id'])
->where(['media_type_id' => 3]);
}]
];
$products = $this->paginate($this->Products);
}
}
选择分页限制:
<select name="products-view" class="form-control products-view inline-pagination-menu" id="products-view">
<option value="3">3</option>
<option value="6">6</option>
<option value="9">9</option>
</select>
Javascript负责更改网址中的limit
$('#products-view').change(function(){
changeLimitPagination(this);
});
function changeLimitPagination(option){
location.search = $.query.set('limit', option.value).toString();
}