具有多个搜索筛选器的Cake PHP3分页
在我的搜索中有四个过滤器。获得搜索结果后,如何使用搜索词分页?它的意思是,若我读到这本书的第二页 分页将不会显示搜索文件管理器表单数据,并显示以下错误具有多个搜索筛选器的Cake PHP3分页,php,cakephp,pagination,cakephp-3.0,Php,Cakephp,Pagination,Cakephp 3.0,在我的搜索中有四个过滤器。获得搜索结果后,如何使用搜索词分页?它的意思是,若我读到这本书的第二页 分页将不会显示搜索文件管理器表单数据,并显示以下错误 Notice (8): Undefined index: to [APP/Controller/Admin/ScheduleController.php, line 257] 控制器代码 public function search() { $this->viewBuilder()->template('a
Notice (8): Undefined index: to [APP/Controller/Admin/ScheduleController.php, line 257]
控制器代码
public function search() {
$this->viewBuilder()->template('allschedule');
$scheduleto = date('Y-m-d', strtotime($this->request->data['to']." +1 days"));
$schedulefrom =date('Y-m-d', strtotime($this->request->data['from']));
if($this->request->data['company'] != 'all' && $this->request->data['gig'] == 'all')
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Job.company' =>$this->request->data['company'],
'Schedule.status !=' =>0,
);
}
elseif($this->request->data['company'] == 'all' && $this->request->data['gig'] != 'all')
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.gig_id' =>$this->request->data['gig'],
'Schedule.status !=' =>0,
);
}
elseif($this->request->data['company'] != 'all' && $this->request->data['gig'] != 'all')
{
$searchfilter = array(
'Job.company' =>$this->request->data['company'],
'Schedule.gig_id' =>$this->request->data['gig'],
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.status !=' =>0,
);
}
else
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.status !=' =>0,
);
}
$this->paginate = [
'fields' => ['User.name', 'Schedule.shift_from', 'Schedule.id', 'Schedule.shift_to', 'Schedule.shift_description', 'Schedule.checkin', 'Schedule.checkout', 'Schedule.start', 'Schedule.stop', 'Schedule.comment', 'Schedule.attested'],
'conditions' => $searchfilter,
'contain' => ['Job','User'],
'order' => [
'shift_from' => 'ASC'
],
'limit' => 30 //'limit'
];
$schedules = $this->paginate($this->Schedule);
$this->set(compact('schedules'));
$this->set('_serialize', ['schedules']);
}
<div class="pagination pagination-large">
<ul>
<?php
echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
?>
</ul>
</div>
公共函数搜索(){
$this->viewBuilder()->模板('allschedule');
$scheduleto=date('Y-m-d',strotime($this->request->data['to'].“+1天”);
$schedulefrom=date('Y-m-d',strotime($this->request->data['from']);
如果($this->request->data['company']!='all'&&$this->request->data['gig']='all')
{
$searchfilter=数组(
“Schedule.shift_from>”=>$schedulefrom,
'Schedule.shift_from<'=>$scheduleto,
'Job.company'=>$this->request->data['company'],
“Schedule.status!=”=>0,
);
}
elseif($this->request->data['company']=='all'&&$this->request->data['gig']!='all')
{
$searchfilter=数组(
“Schedule.shift_from>”=>$schedulefrom,
'Schedule.shift_from<'=>$scheduleto,
'Schedule.gig_id'=>this->request->data['gig'],
“Schedule.status!=”=>0,
);
}
elseif($this->request->data['company']!='all'&&$this->request->data['gig']!='all')
{
$searchfilter=数组(
'Job.company'=>$this->request->data['company'],
'Schedule.gig_id'=>this->request->data['gig'],
“Schedule.shift_from>”=>$schedulefrom,
'Schedule.shift_from<'=>$scheduleto,
“Schedule.status!=”=>0,
);
}
其他的
{
$searchfilter=数组(
“Schedule.shift_from>”=>$schedulefrom,
'Schedule.shift_from<'=>$scheduleto,
“Schedule.status!=”=>0,
);
}
$this->paginate=[
'字段'=>['User.name','Schedule.shift\u from','Schedule.id','Schedule.shift\u to','Schedule.shift\u description','Schedule.checkin','Schedule.checkout','Schedule.start','Schedule.stop','Schedule.comment','Schedule.verified'],
“条件”=>$searchfilter,
'包含'=>['Job','User'],
“订单”=>[
'shift_from'=>'ASC'
],
“限制”=>30/“限制”
];
$schedules=$this->paginate($this->Schedule);
$this->set(紧凑(“时间表”);
$this->set(“_serialize”,[“schedules]”);
}
CTP文件
public function search() {
$this->viewBuilder()->template('allschedule');
$scheduleto = date('Y-m-d', strtotime($this->request->data['to']." +1 days"));
$schedulefrom =date('Y-m-d', strtotime($this->request->data['from']));
if($this->request->data['company'] != 'all' && $this->request->data['gig'] == 'all')
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Job.company' =>$this->request->data['company'],
'Schedule.status !=' =>0,
);
}
elseif($this->request->data['company'] == 'all' && $this->request->data['gig'] != 'all')
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.gig_id' =>$this->request->data['gig'],
'Schedule.status !=' =>0,
);
}
elseif($this->request->data['company'] != 'all' && $this->request->data['gig'] != 'all')
{
$searchfilter = array(
'Job.company' =>$this->request->data['company'],
'Schedule.gig_id' =>$this->request->data['gig'],
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.status !=' =>0,
);
}
else
{
$searchfilter = array(
'Schedule.shift_from > ' => $schedulefrom,
'Schedule.shift_from < ' => $scheduleto,
'Schedule.status !=' =>0,
);
}
$this->paginate = [
'fields' => ['User.name', 'Schedule.shift_from', 'Schedule.id', 'Schedule.shift_to', 'Schedule.shift_description', 'Schedule.checkin', 'Schedule.checkout', 'Schedule.start', 'Schedule.stop', 'Schedule.comment', 'Schedule.attested'],
'conditions' => $searchfilter,
'contain' => ['Job','User'],
'order' => [
'shift_from' => 'ASC'
],
'limit' => 30 //'limit'
];
$schedules = $this->paginate($this->Schedule);
$this->set(compact('schedules'));
$this->set('_serialize', ['schedules']);
}
<div class="pagination pagination-large">
<ul>
<?php
echo $this->Paginator->prev(__('prev'), array('tag' => 'li'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
echo $this->Paginator->numbers(array('separator' => '','currentTag' => 'a', 'currentClass' => 'active','tag' => 'li','first' => 1));
echo $this->Paginator->next(__('next'), array('tag' => 'li','currentClass' => 'disabled'), null, array('tag' => 'li','class' => 'disabled','disabledTag' => 'a'));
?>
</ul>
</div>
上面的代码生成分页,但当它转到分页结果中的下一页时,搜索帖子数据丢失,数据列表显示错误
如何使用筛选器获取分页结果列表
文件管理器表单
<?php echo $this->Form->create('Schedule', array('type' => 'post', 'action' => 'search', 'class'=> 'form-inline'));?>
<div class="form-group">
<div class="form-group" style="padding: 0 0;">
<span style="font-size:12px; display: block;">Company</span>
<?php
echo $this->Form->select('company', $companyarray, array('id' => 'company','escape' => false,'class'=> 'form-control input-sm', 'style'=>'width:160px'));
?>
</div>
<div class="form-group" id="gigselect" style="padding: 0 10px;">
<span style="font-size:12px; display: block;">Gig</span>
<?php
echo $this->Form->select('gig', $searchgigarray, array('id' => 'gig','escape' => false,'class'=> 'form-control input-sm','style'=>'width:160px'));
?>
</div>
<div class="form-group" style="padding: 0 0;">
<span style="font-size:12px; display: block;">From</span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="from" name="from" type="text" value="<?php echo $backdate;?>" class="form-control input-sm" style="width:120px">
</div>
</div>
<div class="form-group" style="padding: 0 10px;">
<span style="font-size:12px; display: block;">To</span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="to" name="to" type="text" value="<?php echo $frontdate;?>" class="form-control input-sm" style="width:120px">
</div>
</div>
<div class="form-group" style="padding: 0 0; margin-top:15px;">
<div class="input-group">
<?php echo $this->Form->submit('OK',array('class'=>'btn btn-success','style'=>"height: 2em;")); ?>
</div>
</div>
</div>
<?php echo $this->Form->end() ?>
公司
现场演奏会
从…起
提交表单时未发生错误的原因是服务器中存在$\u POST
变量
但是如果您单击页面按钮,即
,则$\u POST
将消失
这就是为什么会发生这种情况
注意(8):未定义索引:至[APP/Controller/Admin/ScheduleController.php,第257行]
要解决此问题,请更改获取的方法
<?php echo $this->Form->create('Schedule', array('type' => 'get', 'action' => 'search', 'class'=> 'form-inline'));?>
<div class="form-group">
<div class="form-group" style="padding: 0 0;">
<span style="font-size:12px; display: block;">Company</span>
<?php
echo $this->Form->select('company', $companyarray, array('id' => 'company','escape' => false,'class'=> 'form-control input-sm', 'style'=>'width:160px'));
?>
</div>
<div class="form-group" id="gigselect" style="padding: 0 10px;">
<span style="font-size:12px; display: block;">Gig</span>
<?php
echo $this->Form->select('gig', $searchgigarray, array('id' => 'gig','escape' => false,'class'=> 'form-control input-sm','style'=>'width:160px'));
?>
</div>
<div class="form-group" style="padding: 0 0;">
<span style="font-size:12px; display: block;">From</span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="from" name="from" type="text" value="<?php echo $backdate;?>" class="form-control input-sm" style="width:120px">
</div>
</div>
<div class="form-group" style="padding: 0 10px;">
<span style="font-size:12px; display: block;">To</span>
<div class="input-group">
<span class="input-group-addon"><i class="fa fa-calendar"></i></span>
<input id="to" name="to" type="text" value="<?php echo $frontdate;?>" class="form-control input-sm" style="width:120px">
</div>
</div>
<div class="form-group" style="padding: 0 0; margin-top:15px;">
<div class="input-group">
<?php echo $this->Form->submit('OK',array('class'=>'btn btn-success','style'=>"height: 2em;")); ?>
</div>
</div>
</div>
<?php echo $this->Form->end() ?>
希望这能有所帮助。您能在这里包括您的表单$searchfilter
值不是来自$\u GET
。它如下所示search?page=4&sort=Schedule.shift\u from&direction=ASC
实际上,如果单击页面按钮,$\u POST数据将不再存在,这就是为什么必须使用$\u GET而不是$_POST@NewbeeDev使用表单更新帖子,但所有文件管理器参数都不在$\u GET中。搜索参数不是如此,这将做你想要的(PRG),它会做得很好,干净。