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.