Home > Backend Development > PHP Tutorial > yii?CDbCriteria

yii?CDbCriteria

WBOY
Release: 2016-06-23 13:30:21
Original
1010 people have browsed it


选择 Date Form 和 Date To,点 Search按钮,会查询出这两个日期间的数据  public function search() {        $criteria = new CDbCriteria;        if(isset($_GET['date1'])&&isset($_GET['date2'])){            $criteria->addBetweenCondition('news_date',$_GET['date1'], $_GET['date2']);        }        //这个功能已经实现        //现在的问题是:如果用户只选择了 Date Form,就显示Date Form 这个日期之后的所有数据       // 只选择了 Date To就显示Date To 这个日期之前的所有数据                              return new CActiveDataProvider($this, array(            'criteria' => $criteria,        ));    }
Copy after login


回复讨论(解决方案)

给你代码,几乎差不多

public function failureCat()        {                $criteria = new CDbCriteria;                $criteria->compare('t.failItem', $this->failItem);                $criteria->compare('logInfo.logProcess', $this->failStation);                $criteria->compare('logInfo.logUpdate', '>=' . $this->dateToDatetime($this->startDate, 1));                $criteria->compare('logInfo.logUpdate', '<=' . $this->dateToDatetime($this->endDate));                $criteria->with = array('logInfo');                return new CActiveDataProvider('TestLogFail', array(                    'pagination' => array(                        'pageSize' => Yii::app()->params['pageSize'],                    ),                    'criteria' => $criteria,                    'sort' => array(                        'defaultOrder' => 'logInfo.logUpdate desc',                    ),                ));        }
Copy after login

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template