Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/date/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Date CakePHP搜索插件重新填充日期_Date_Cakephp_Search_Plugins - Fatal编程技术网

Date CakePHP搜索插件重新填充日期

Date CakePHP搜索插件重新填充日期,date,cakephp,search,plugins,Date,Cakephp,Search,Plugins,我在用电脑 我在日期之间进行了过滤,但在执行搜索后,日期下拉列表不会重新填充搜索的日期 有人能找出为什么我的日期表没有重新填充吗?我想这可能是因为我正在或条件中将日期转换为字符串,但据我所知,或条件需要字符串 代码如下: 模型 尝试将$endDateFieldOptions['selected']=array(…)更改为$endDateFieldOptions['default']=array(…)当然$fromDate也是如此……只需使用echo$this->Form->create('Mov

我在用电脑

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

有人能找出为什么我的日期表没有重新填充吗?我想这可能是因为我正在或条件中将日期转换为字符串,但据我所知,或条件需要字符串

代码如下:

模型


尝试将
$endDateFieldOptions['selected']=array(…)
更改为
$endDateFieldOptions['default']=array(…)
当然$fromDate也是如此……只需使用
echo$this->Form->create('MovieStar')
。无需手动调整url。谢谢你的建议。Arilia-$endDateFieldOptions['default']修复了它。马克:你的建议没有解决问题,但一切照旧。我很高兴删除不必要的代码!还有一个关于搜索的问题你们可以帮我。请
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'));