First should declare two variables in model
public $from_date,$to_date;
Then add following lines in the search function [model]
if(!empty($this->to_date) && !empty($this->from_date))
{
$criteria->condition = "dat between '$this->from_date' and '$this->to_date'";
}
The following lines need in the view file to display form
<div id="search">
$this->beginWidget('zii.widgets.CPortlet', array(
'title'=>"Search",
));
<?php
$form=$this->beginWidget('CActiveForm', array( 'id'=>'page-form', 'enableAjaxValidation'=>true,));
?>
<b>From :</b>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'from_date', // name of post parameter
'value'=> '',//Yii::app()->request->cookies['from_date']->value,
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
<br /><b>To :</b>
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'to_date',
'value'=> '',//Yii::app()->request->cookies['to_date']->value,
'options'=>array(
'showAnim'=>'fold',
'dateFormat'=>'yy-mm-dd',
),
'htmlOptions'=>array('style'=>'height:20px;),));
?>
<?php echo CHtml::submitButton('Search',array('id'=>'searchbtn')); ?>
[b]<?php $this->endWidget(); ?>[/b]
<?php $this->endWidget();?>
</div>
Finally add following lines in the controller/admin function
if(!empty($_POST))
{
$model->from_date = $_POST['from_date'];
$model->to_date = $_POST['to_date'];
}
Thats it!