我目前正在开发一些东西,我在这里遇到问题..每次添加一年的搜索表单时,我的分页设置都无法正常工作..
模型分页函数
/**
* generate settings for pagination
* @return array $settings
*/
public function generateSettingsForPager($transportId, $year){
$conditions['delete_flag'] = 0;
if($transportId){
$conditions['transport_id'] = $transportId;
}
if($year){
$conditions['year'] = $year;
}
$settings = array (
'fields' => 'id, year, transport_id, item, description, currency, all_in_php',
'limit' => 30,
'recursive' => -1,
'order' => array(
'id' => 'desc'
),
'conditions' => $conditions
);
return $settings;
}
控制器(索引/视图功能)
public function index(){
$getData = $this->request->query;
$transportId = isset($getData['transport_id']) ? $getData['transport_id'] : null;
$year = isset($getData['year']) ? $getData['year'] : null;
$this->paginate = $this->UpgradingAndModification->generateSettingsForPager($transportId, $year);
$upgradingAndModifications = $this->paginate('UpgradingAndModification');
$this->set('transportId', $transportId);
$this->set('year', $year);
$this->set('upgradingAndModifications', $upgradingAndModifications);
}
索引/查看搜索表单
<?php echo $this->Form->create('search',array('url' => '/upgradingAndModifications/index','type' => 'get')); ?>
<div class="well">
<div class="pull-left">
<?php
echo $this->Form->input('transport_id', [
'options' => $this->App->getTransportNames(),
'style' => 'margin-right:50px',
'tabindex' => '15',
'label' => 'Transport',
'empty' => 'Select Transport Name',
'default' => (isset($transportId)) ? $transportId : ''
])."  ";
?>
</div>
<div>
<?php echo $this->Form->input('year',
[
'empty' => 'Choose a year',
'class' => 'space-right-10',
'type' => 'date',
'dateFormat' => 'Y',
'minYear' => date('Y') - 100,
'maxYear' => date('Y'),
'selected' => (isset($year)) ? $year : ''
])."  ";
?>
</div>
<input type="submit" value="search" class="btn btn-primary btn-sm" id="searchButton">
</div>
<?php echo $this->Form->end();?>
帮助将不胜感激!..谢谢!..
答案 0 :(得分:0)
对不起这个非常晚的更新人员。我设法解决了这个问题,只需在我的“年份”搜索表单中将所选内容更改为值即可。这条线变成了 -
'value'=&gt; (isset($ year))? $ year:'',
而不是 -
'selected'=&gt; (isset($ year))? $ year:'',