[英]Filter Date using Date Picker in Yii
I have generated my crud screens using gii.. I have a search form, where i have put a date picker, where i give the user to select the date he wants. 我已经使用gii生成了原始屏幕。我有一个搜索表单,在其中放置了一个日期选择器,在其中给用户选择他想要的日期。
But the problem is that i have the date stored in seconds in the database. 但是问题是我在数据库中存储了以秒为单位的日期。
and i know that i can convert the date using strtotime. 而且我知道我可以使用strtotime转换日期。 But then how do i filter using the search method in my model? 但是,如何在模型中使用搜索方法进行过滤?
this is my date picker 这是我的约会选择器
<?php
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'name'=>'ordering_date',
'id'=>'ordering_date',
// additional javascript options for the date picker plugin
'options'=>array(
'showAnim'=>'fold',
),
'htmlOptions'=>array(
'style'=>'height:20px;'
),
));
?>
and this is my search method in my model. 这是我在模型中的搜索方法。 I want to compare the ordering_date 我想比较ordering_date
public function search()
{
// Warning: Please modify the following code to remove attributes that
// should not be searched.
//echo $this->ordering_date;
$criteria=new CDbCriteria;
$criteria->compare('order_id',$this->order_id);
$criteria->compare('customer_id',$this->customer_id);
$criteria->compare('delivery_address_id',$this->delivery_address_id);
$criteria->compare('billing_address_id',$this->billing_address_id);
$criteria->compare('ordering_date',$this->ordering_date);
$criteria->compare('ordering_done',$this->ordering_done,true);
$criteria->compare('ordering_confirmed',$this->ordering_confirmed);
$criteria->compare('payment_method',$this->payment_method);
$criteria->compare('shipping_method',$this->shipping_method);
$criteria->compare('comment',$this->comment,true);
$criteria->compare('status',$this->status,true);
$criteria->compare('total_price',$this->total_price);
return new CActiveDataProvider($this, array(
'criteria'=>$criteria,
));
}
Try this: 尝试这个:
$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'ordering_date',
'options' => array('dateFormat' => 'mm-dd-yy',),
And search 并搜索
$begindate = CDateTimeParser::parse($this->ordering_date, 'MM-dd-yyyy');
$enddate = $begindate + 24* 60*60;
$criteria->addBetweenCondition('ordering_date', $begindate, $enddate);
Either do a $this->ordering_date = strtotime($this->ordering_date);
要么执行$this->ordering_date = strtotime($this->ordering_date);
before you compare or $criteria->compare('ordering_date', strtotime($this->ordering_date));
比较之前或$criteria->compare('ordering_date', strtotime($this->ordering_date));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.