Pagination 使用带有高级过滤器的cakephp分页

Pagination 使用带有高级过滤器的cakephp分页,pagination,cakephp-2.0,Pagination,Cakephp 2.0,我在电子商务网站上的工作,我需要一些像价格,类型等先进的过滤器 控制器 public function index($category) { $this->set('category',$category); $this->loadModel("Product"); $conditions['Product.category'] = $category; if(!empty($this->request->data['filter']['material

我在电子商务网站上的工作,我需要一些像价格,类型等先进的过滤器

控制器

public function index($category) {
$this->set('category',$category);
$this->loadModel("Product");    

$conditions['Product.category'] = $category;    
if(!empty($this->request->data['filter']['materialtype']))
{
foreach($this->request->data['filter']['materialtype'] as $v)
{       
$this->set('v',$v); 
$conditions['OR'][]['Product.materialtype LIKE'] ="%$v%";
}
}
$this->set('agetProduct',$this->paginate($conditions)); 
}

查看

初始查询工作正常

1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
 1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%')) LIMIT 12

2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%'))
1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12, 12      5   5   1
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
当我点击ADVANCE FILTER复选框时,下面的查询是GENERATE,这也很好。这个MYSQL查询包含14条记录,其中12个产品设置在第一页,其余产品设置在第二页

1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
 1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%')) LIMIT 12

2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%'))
1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12, 12      5   5   1
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
但要查看过滤查询的下一个产品,当我单击下一页时,我的查询已完全更改,现在我看到以下查询,其中包含SQL表的所有记录

1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
 1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%')) LIMIT 12

2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' AND ((`Product`.`materialtype` LIKE '%Yellow Gold%') OR (`Product`.`materialtype` LIKE '%White Gold%') OR (`Product`.`materialtype` LIKE '%Silver%'))
1 SELECT `Product`.`id`, `Product`.`category`, `Product`.`materialtype`, `Product`.`occasion`, `Product`.`collections`, `Product`.`stone`, `Product`.`sku`, `Product`.`name`, `Product`.`goldkaratage`, `Product`.`weight`, `Product`.`stoneweight`, `Product`.`diamondcaratage`, `Product`.`diamondcolor`, `Product`.`diamondclarity`, `Product`.`picture1`, `Product`.`picture2`, `Product`.`picture3`, `Product`.`picture4`, `Product`.`picture5`, `Product`.`picture6`, `Product`.`price`, `Product`.`description`, `Product`.`featured`, `Product`.`action` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant' LIMIT 12, 12      5   5   1
2   SELECT COUNT(*) AS `count` FROM `mookim`.`products` AS `Product` WHERE `Product`.`category` = 'Pendant'
控制器

if(!empty($this->params['url']['data']['filter']['materialtype']))
{   
foreach ($this->params['url']['data']['filter']['materialtype'] as $v){
$conditions['OR'][]['Product.materialtype LIKE'] ="%$v%";
}
}


$this->paginate = array('limit' => 12,'conditions' => $conditions);
$agetProduct = $this->paginate($this->modelClass);
$this->set(compact('agetProduct'));   
}
查看使用表单方法获取

<?php echo $this->Form->create('filter', array('url'=>array('controller'=>'Products', 'action'=>'index',$category),'id'=>'filter','autocomplete'=>'off','type'=>'get'));?>