带有搜索表单的 CAKEPHP 分页设置

CAKEPHP Pagination Settings with Search Form

我目前正在开发一些东西,但我在这里遇到了一个问题。每次我添加年份的搜索表单时,我的分页设置都不起作用。

模型分页功能

/**
 * 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;
}

控制器(index/view 函数)

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

Index/View 搜索表单

<?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 : ''
            ])."&nbsp&nbsp";
        ?>
    </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 : ''
            ])."&nbsp&nbsp";
        ?>
    </div>
    <input type="submit" value="search" class="btn btn-primary btn-sm" id="searchButton">
</div>
<?php echo $this->Form->end();?>

将不胜感激!...谢谢!...

抱歉更新晚了各位。我设法通过简单地将 "year" 搜索表单中的 selected 更改为 value 来解决这个问题。所以这条线变成了-

'value' => (isset($year)) ? $年份 : ' ',

而不是-

'selected' => (isset($year)) ? $年份 : ' ',