CakePHP搜索插件重新填充日期

时间:2014-03-07 19:11:30

标签: date cakephp search plugins

我正在使用search plugin by CakeDC

我在日期工作之间进行了过滤,但在执行搜索后,日期下拉列表不会重新填充搜索日期。

有人能弄清楚为什么我的约会表格没有重新填充吗?我认为这可能是因为我将日期转换为条件中的字符串,但据我所知,条件需要一个字符串。

以下是代码:

模型

public $filterArgs = array(
'from_date'  => array('type' => 'query', 'method' => 'orConditionsFromDate'),
'end_date'   => array('type' => 'query', 'method' => 'orConditionsEndDate'),
);

public function orConditionsFromDate($data = array()) {
    $filterFrom = $data['from_date'];
    $fromString = "$filterFrom[year]-$filterFrom[month]-01";
    $cond = array(
            'MovieStar.reject_date >=' => $fromString,
        );
    return $cond;
}

public function orConditionsEndDate($data = array()) {
    $filterEnd = $data['end_date'];
    $endString = "$filterEnd[year]-$filterEnd[month]-$filterEnd[day]";
    debug('$data');
    debug($data);
    $cond = array(
            'MovieStar.reject_date <=' => $endString,
        );
    return $cond;
}

public function getFromDateFormOptions(){
    $dateFieldOptions['type'] = 'date';
    $dateFieldOptions['div'] = array( 'style' => 'width:180px');
    $dateFieldOptions['required'] = false;
    $dateFieldOptions['maxYear'] = date('Y');

    $fromDateFieldOptions = $dateFieldOptions;
    $fromMonth =  date('m') - 1;
    $fromYear =  date('Y');
    if($fromMonth == 0){
        $fromMonth = 12;
        $fromYear = $fromYear - 1;
    }
    $fromDateFieldOptions['selected'] = array('day' => 1, 'month' => $fromMonth, 'year' => $fromYear  );
    $fromDateFieldOptions['label'] = 'From';
    //$myFromDateFormField = $this->Form->input('from_date', $fromDateFieldOptions);
    //return $myFromDateFormField;
    return $fromDateFieldOptions;
}

public function getEndDateFormOptions(){
    $dateFieldOptions['type'] = 'date';
    $dateFieldOptions['div'] = array( 'style' => 'width:180px');
    $dateFieldOptions['required'] = false;
    $dateFieldOptions['maxYear'] = date('Y');

    $endDateFieldOptions = $dateFieldOptions;
    $endDate = date('t');  // last day of current month
    $endDateFieldOptions['selected'] = array('day' => $endDate, 'month' => date('m'), 'year' => date('Y'));
    $endDateFieldOptions['label'] = 'To';
    //$myEndDateFormField = $this->Form->input('end_date', $endDateFieldOptions);
    //return $myEndDateFormField;   
    return $endDateFieldOptions;
}

查看:

    <?php 
    echo $this->Form->create('MovieStar', array(
        'url' => array_merge(array('action' => 'index'), $this->params['pass'])
    ));
?>
<table>
    <tr>
    <td>
        <?php   echo $this->Form->input('from_date', $myFromDateFormOptions); ?>
    </td>
    <td>
        <?php   echo $this->Form->input('end_date', $myEndDateFormOptions); ?>
    </td>
    </tr>
</table>

<?php
    echo $this->Form->submit(__('Search'), array());
    echo $this->Form->end(); 
?>

控制器

    $myFromDateFormOptions = $this->MovieStar->getFromDateFormOptions();
    $myEndDateFormOptions = $this->MovieStar->getEndDateFormOptions();


    $this->set(compact('myFromDateFormOptions'));
    $this->set(compact('myEndDateFormOptions'));

0 个答案:

没有答案