Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.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
日期字段搜索不筛选';年月日';格式-YII框架_Yii - Fatal编程技术网

日期字段搜索不筛选';年月日';格式-YII框架

日期字段搜索不筛选';年月日';格式-YII框架,yii,Yii,CJUIDatePicker不过滤dd/mm/yyyy格式的值,但过滤如果我手动提供DB日期格式,如图所示,我已附上所有代码,包括搜索面板和日期小部件的视图和型号,请查看此 我的模型搜索() 我对CGridView的看法 <?php $this->widget('zii.widgets.grid.CGridView', array( 'id'=>'basecontact-grid', 'dataProvider'=>$model->search(),

CJUIDatePicker不过滤dd/mm/yyyy格式的值,但过滤如果我手动提供DB日期格式,如图所示,我已附上所有代码,包括搜索面板和日期小部件的视图和型号,请查看此

我的模型搜索()

我对CGridView的看法

<?php $this->widget('zii.widgets.grid.CGridView', array(
    'id'=>'basecontact-grid',
    'dataProvider'=>$model->search(),
    //'filter'=>$model,
    'columns'=>array(
        array('class'=>'CButtonColumn',),
        'name',
        'crm_base_contact_id',      
                   array(
            'name'=>'is_active',
            'filter'=>CHtml::dropDownList('Event[is_active]', '',  
                array(
                    ''=>'',
                    '1'=>'Y',
                    '0'=>'N',
                )
            ),
            'value' =>'($data->is_active==1)?"Y":"N"',
        ),
        'created',
        'createdby',
        'description',
    ),
)); ?>

您可能应该更改日期格式。将其设置为“dateFormat”=>“dd-mm-yy”

$this->widget('zii.widgets.jui.CJuiDatePicker', array(
'model'=>$model,
'attribute'=>'dob',
// additional javascript options for the date picker plugin
'options' => array(
'showAnim' => 'fold',
'dateFormat'=>'dd/mm/yyyy',
),
'htmlOptions' => array(
'style' => 'height:20px;'
),
));
更新:

在您的模型中,定义如下,在我的例子中,dob是属性名。你可以有自己的

在运行任何查找之前,这将在内部将日期格式从“dd/mm/yyyy”更改为“yyyy-mm-dd”

参考:

更新2

将您的搜索方法替换为:

public function search() {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbCriteria;

    $criteria->compare('crm_base_contact_id', $this->crm_base_contact_id);
    $criteria->compare('name', $this->name, true);    
    $criteria->compare('created', '07/12/2013'); //date('Y-m-d', strtotime($this->created))
    $criteria->compare('createdby', $this->createdby, true);
    $criteria->compare('description', $this->description);
    $criteria->compare('is_active', $this->is_active);
    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}
更新3 将此行
$criteria->compare('created','07/12/2013');
更改为

$criteria->compare('created', date('Y-m-d', strtotime($this->created));

是的,我在CjuiDatePicker小部件中设置了dateformat=“dd/mm/yyyy”,如果我输入“yyy-mm-dd”,当我以该格式单击小部件中的日期时,它不会过滤“在CjuiDatePicker文本字段中手动设置格式,并对其进行搜索筛选。请看附件中的图片,并告诉我为什么不在CjuiDatePicker小部件中将dateformat更改为yyyy mm dd?这很奇怪。你们能和我分享一下你们是如何在数据库中创建存储的吗?哪种格式?这应该适合你,$criteria->compare('created',date('Y-m-d',strottime($This->created));据我所知,上面的答案应该适合你。现在你可以包括hh:mm:ss并尝试一下。例如,$criteria->compare('created',date('Y-m-d H:i:s',strottime($This->created));
protected function beforeFind()
{
$this->dob=date('Y-m-d', strtotime($this->dob)); 
parent::beforeFind();
}
public function search() {
    // @todo Please modify the following code to remove attributes that should not be searched.

    $criteria = new CDbCriteria;

    $criteria->compare('crm_base_contact_id', $this->crm_base_contact_id);
    $criteria->compare('name', $this->name, true);    
    $criteria->compare('created', '07/12/2013'); //date('Y-m-d', strtotime($this->created))
    $criteria->compare('createdby', $this->createdby, true);
    $criteria->compare('description', $this->description);
    $criteria->compare('is_active', $this->is_active);
    return new CActiveDataProvider($this, array(
        'criteria' => $criteria,
    ));
}
$criteria->compare('created', date('Y-m-d', strtotime($this->created));