2017-07-26 2 views
0

私はeコマースのウェブサイトで、価格、種類などの事前フィルタが必要です。advance filterでcakephpページネーションを処理しています

コントローラ

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)); 

}

表示 enter image description here

最初のクエリWORKING FINE

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' 
私は以下のクエリADVANCEフィルタチェックボックスをクリックします

もFINE THIS MYSQLのQUERYは、最初のページとREST ON SET 12社の製品は、2ページ目にある14 RECORD

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%')) 

が含まれていますが、確認することですWHICH GENERATE IS私は次のページをクリックフィルタクエリの次の製品は、MY QUERY COMPLETELY SQLのテーブルのすべてのレコードが含まれ、今私は以下を参照してくださいQUERYを変更し

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' 

答えて

0
public function index($category) { 
$this->set('category',$category); 
$this->loadModel("Product");  
$conditions['Product.category'] = $category;  

CONTROLLER

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')); 
} 

VIEW使用形態の方法はGET

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