YII filtering by date does not work. why?

Source: Internet
Author: User
YII filtering by date does not work. why? Yii PHP date filtering

YII filtering by date does not work. why?

Model

 True), array ('time', 'Safe '), // The following rule is used by search (). // Please remove those attributes that shocould not be searched. array ('Id, Time', 'Safe ', 'on' => 'Search'),);}/*** @ return array relational rules. */public function relations () {// NOTE: you may need to adjust the relation name and the related // class name for the relations automatically generated below. return array ();}/*** @ return Array customized attribute labels (name => label) */public function attributeLabels () {return array ('id' => 'number ', 'Time' => 'time',);}/*** Retrieves a list of models based on the current search/filter conditions. * @ return CActiveDataProvider the data provider that can return the models based on the search/filter conditions. */public function search () {// Warning: Please modify the following code to rem Ove attributes that // shocould not be searched. $ criteria = new CDbCriteria; $ criteria-> compare ('id', $ this-> id); $ criteria-> compare ('time', '> = '. $ this-> starttime); $ criteria-> compare ('time', '<= '. $ this-> endtime); // whether to enable fuzzy search. return new CActiveDataProvider ($ this, array ('criteria '=> $ criteria, // 'pagination' => array ('pagesize' => $ pagesize? Pagesize: $ page), // 'pagination' => array ('pagesize' => $ page ),));}}




View




Controller

public function actionTimefliter(){$model=new Timefliter();$this->render('timefliter',array('model'=>$model,));}


Reply to discussion (solution)

After submission, I didn't assign the obtained date value to the model. how can I filter the data in the search method?

How to copy data to a model

You can use another solution to create a new dataprovinder and then query records between time points in SQL statements.

$ Model-> startTime =$ _ POST ['starttime']; // pass the value to the model $ model-> endTime =$ _ POST ['endtime'];


Thanks for the two upstairs. both methods are feasible, but the second method is slow.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.