在我的搜索中有四個過濾器。獲得搜索結果後,如何與搜索條件分頁?它的意思是如果我去 分頁搜索過濾器表單數據的第二頁將不會出現,並顯示以下錯誤蛋糕PHP3分頁與多個搜索過濾器
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']);
}
CTP文件
<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>
上面的代碼生成分頁,但是當它轉到下一頁時分頁年齡導致搜索POST數據丟失,數據列表顯示錯誤。
我怎樣才能得到帶過濾器的分頁結果列表?
文件管理器表
<?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() ?>
你可以在這裏包括你的表格 – Beginner
'$ searchfilter'值不是來自$ _GET'。它來自下面 'search?page = 4&sort = Schedule.shift_from&direction = ASC' – Miuranga
實際上,如果您單擊頁面按鈕$ _POST數據將不再存在,這就是爲什麼您必須使用$ _GET而不是$ _POST – Beginner