CakeDCで日付検索を行うには2つの方法があります。
最初:特定の年だけを探します
モデルで
'creationdate' => array('type' => 'like'),
コントローラーアクション:
$this->Prg->commonProcess();
if(array_key_exists('creationdate',$this->passedArgs))
$this->passedArgs['creationdate'] = $this->passedArgs['creationdate']['year'];
とビューで:
echo $this->Form->input('creationdate', array(
'label' => __('Creation date'),
'dateFormat' => 'Y',
'minYear' => date('Y') - 100,
'maxYear' => date('Y'),
'empty' => true
)
);
2番目の方法:日付の範囲を探す
モデル内:
'creationDateBetween' => array(
'type' => 'expression',
'method' => 'CreationDateRangeCondition',
'field' => 'MODEL.creationdate BETWEEN ? AND ?',
),
public function CreationDateRangeCondition($data = array()){
if(strpos($data['creationDateBetween'], ' - ') !== false){
$tmp = explode(' - ', $data['creationDateBetween']);
$tmp[0] = $tmp[0]."-01-01";
$tmp[1] = $tmp[1]."-12-31";
return $tmp;
}else{
return array($data['creationDateBetween']."-01-01", $data['creationDateBetween']."-12-31");
}
}
ビューで:私は年の範囲にスライダーを使用していることに注意してください
echo $this->Form->input('creationDateBetween',
array(
'label' => __('Creation date between X and Y'),
'div' => false,
'style' => 'border: 0; color: #49AFCD; font-weight: bold;'
)
);
?><div id="creationDateBetweenSlider" style="padding:0;"></div><?php
<script>
$(function() {
var creationDateBetweenSlider = $( "#creationDateBetweenSlider" ),
institutionCreationDateBetween = $( "#MODELCreationDateBetween" ),
lock = 0;
creationDateBetweenSlider.slider({
range: true,
min: 1900,
max: 2050,
values: [ 2000, 2013 ],
slide: function( event, ui ) {
MODELCreationDateBetween.val( ui.values[ 0 ] + " - " + ui.values[ 1 ] );
}
});
if(lock != 0) MODELCreationDateBetween.val( creationDateBetweenSlider.slider( "values", 0 ) + " - " + creationDateBetweenSlider.slider( "values", 1 ) );
lock = 1;
});
</script>
それが役に立てば幸い !