cakephp分页从数组设置条件
cakephp pagination set condistion from array
我正在使用一个带有多个复选框的表单,我只需要显示复选框类别中的那些数据。
条件怎么写。
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');
但是出现错误。
提前致谢
您似乎正在使用字符串连接而不是数组来构建条件数组。
我也不清楚过滤器传递的是一组字符串还是整数。
我想你可以试试:
// 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.
之前准备好你的数据
我正在使用一个带有多个复选框的表单,我只需要显示复选框类别中的那些数据。 条件怎么写。
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');
但是出现错误。 提前致谢
您似乎正在使用字符串连接而不是数组来构建条件数组。 我也不清楚过滤器传递的是一组字符串还是整数。 我想你可以试试:
// 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.
之前准备好你的数据