2015-07-20 23 views
0

我正在使用一個窗體有幾個複選框,我只需要顯示那些在複選框類別中的數據。 如何爲此寫入條件。cakephp從列表中分頁設置condistion

for($i=0;$i<count($this->request->data['filter']['delivering']);$i++) 
{ 
$opt1=".'Gig.bangsalsodeliverings' => ".$this->request->data['filter']['delivering'][$i]; 
$opt2=$opt2.$opt1.','; 
} 
$options=array('conditions' => array($opt2)); 
$this->Paginator->settings = $options; 
$agetGigsItem = $this->Paginator->paginate('Gig'); 

但是出現錯誤。 在此先感謝

回答

0

看來你正在使用字符串contatenation而不是數組來構建條件數組。 另外,我不清楚,如果過濾器交付是一組字符串或整數。 我想你可以嘗試:

// Merge the filters into a csv string 
$filters = array(); 
foreach($this->request->data['filter']['delivering'] as $v){ 
    $filters[] = "'{$v}'"; 
} 
$csv_filters = implode(",", $filters); 

// Use the csv to make a IN condition 
$this->Paginator->settings = array('conditions' => array(
    "Gig.bangsasodeliverings IN ({$csv_filters})", 
)); 

請注意,SQL注入可以在這裏做,所以創建$ csv_filters之前準備數據。

+0

thanx for reply其實我需要過濾器像電子商務網站一樣,當我點擊一個品牌,然後顯示同一品牌的所有產品 – ggutigod

+0

我需要更多的幫助,我需要設置選定的那些複選框。 echo'this-> Form-> input('deliver。',array('hiddenField'=> false,'type'=>'checkbox','value'=> $ agetalsodelivering [$ i] ['Bangsalsodelivering'] [ '名稱'], 'DIV'=> '複選框', '類'=> 'checkboxfilter', 'ID'=> $ agetalsodelivering [$ i]於[ 'Bangsalsodelivering'] [ '名稱'], '標籤'=> $ agetalsodelivering [$ i]於[ 'Bangsalsodelivering'] [ '名稱'])); – ggutigod

+0

已經在這裏回答:http://stackoverflow.com/questions/12168225/multiple-checkboxes-in-cakephp-how-to-set-which-are-checked –