I am following the instructions here http://www.yiiframework.com/doc-2.0/guide-output-data-widgets.html#separate-filter-form
to create a simple search for dates in a range.
Instead of simple text fields, im just using kartik datepicker to select the dates
use kartik\date\DatePicker;
<?= $form->field($model, 'saleFrom')->widget(DatePicker::className(), [
'options' => ['placeholder' => 'FROM'],
'pluginOptions' => [
'autoclose' => true,
'format' => 'yyyy/mm/dd'
]
]); ?>
<?= $form->field($model, 'saleTo')->widget(DatePicker::className(), [
'options' => ['placeholder' => 'TO'],
'pluginOptions' => [
'autoclose' => true,
'format' => 'yyyy/mm/dd'
]
]); ?>
As per docs, i included the fields in my search model and added the where filters to the query:
public $saleFrom;
public $saleTo;
$query->andFilterWhere(['>=', 'sale_date', $this->saleFrom])
->andFilterWhere(['<=', 'sale_date', $this->saleTo]);
I vardumped the saleFrom/saleTo, and they correctly contain the dates i’ve selected via the widget.
Basically, nothing happens - page just refreshes and filters dont seem to work.
That query where filter is exactly as per docs - do i assume Yii just handles the date conversion and/or sql clause ?
Ie, mysql is storing the sale_date in format "2016-04-30", saleFrom/saleTo contains "2016/04/30" ?
Can anyone walk me through getting this to work, been stuck on it a couple of days.
thanks much