【问题标题】:cakephp pagination set condistion from arraycakephp分页从数组中设置条件
【发布时间】:2015-07-20 18:42:41
【问题描述】:

我正在使用带有多个复选框的表单,我只需要显示复选框类别中的那些数据。 如何为此编写条件。

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

但出现错误。 提前致谢

【问题讨论】:

    标签: cakephp pagination string-concatenation


    【解决方案1】:

    您似乎使用字符串连接而不是数组来构建条件数组。 我也不清楚过滤器提供的是一组字符串还是整数。 我想你可以试试:

    // 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之前准备好你的数据。

    【讨论】:

    • 感谢回复实际上我需要像电子商务网站一样的过滤器,例如当我点击一个品牌时,它会显示同一品牌的所有产品
    • 我需要更多帮助来设置选中的那些复选框。 echo $this->Form->input('delivering.',array('hiddenField' => false,'type'=>'checkbox','value'=>$agetalsodelivering[$i]['Bangsalsodelivering'][ 'name'],'div'=>'checkbox','class'=>'checkboxfilter','id'=>$agetalsodelivering[$i]['Bangsalsodelivering']['name'],'label'=> $agetalsodelivering[$i]['Bangsalsodelivering']['name']));
    猜你喜欢
    • 1970-01-01
    • 2020-06-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-03-12
    • 2014-03-13
    • 1970-01-01
    相关资源
    最近更新 更多