您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

YII 按照日期过滤不起作用,怎么回事?

2025/4/27 6:19:53发布21次查看
yii php 日期过滤
yii  按照日期过滤不起作用,怎么回事?
模型
true), array('time', 'safe'), // the following rule is used by search(). // please remove those attributes that should 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'=> '编号', '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 remove attributes that // should not be searched. $criteria=new cdbcriteria; $criteria->compare('id',$this->id); $criteria->compare('time','>='.$this->starttime); $criteria->compare('time','endtime); //是否开启模糊搜索,在后面true中实现 return new cactivedataprovider($this, array( 'criteria'=>$criteria, //'pagination'=>array('pagesize'=>$pagesize?pagesize:$page), //'pagination'=>array('pagesize'=>$page), )); }}
视图
开始时间widget('zii.widgets.jui.cjuidatepicker',array( 'language'=>'zh_cn', 'name'=>'starttime', 'value'=>$query['start'] ? $query['start'] : date('y-m-d'), 'options'=>array( 'showanim'=>'fold', 'showon'=>'both', 'buttonimage'=>yii::app()->request->baseurl.'/images/calendar.gif', //'maxdate'=>'new date()', 'buttonimageonly'=>true, 'dateformat'=>'yy-mm-dd', ), 'htmloptions'=>array( 'style'=>'height:18px', 'maxlength'=>8, ), )); //echo $value;exit; //http://blog.csdn.net/dreamzml/article/details/8227646?> 结束时间widget('zii.widgets.jui.cjuidatepicker',array( 'language'=>'zh_cn', 'name'=>'endtime', 'value'=>$query['end'] ? $query['end'] : date('y-m-d'), 'options'=>array( 'showanim'=>'fold', 'showon'=>'both', 'buttonimage'=>yii::app()->request->baseurl.'/images/calendar.gif', //'maxdate'=>'new date()', 'buttonimageonly'=>true, 'dateformat'=>'yy-mm-dd', ), 'htmloptions'=>array( 'style'=>'height:18px', 'maxlength'=>8, ), )); ?>
控制器
public function actiontimefliter() { $model=new timefliter(); $this->render('timefliter',array('model'=>$model,)); }
回复讨论(解决方案) 提交之后又没把获取的日期值赋值给模型,那在search方法中怎么会过滤
怎么复制给模型
可以用另外一种解决方案,自己新建一个dataprovinder 然后sql语句查询时间之间的记录
$model->starttime=$_post['starttime']; //传值给模型$model->endtime=$_post['endtime'];
谢谢楼上两位,都搞定了,两种方法都是可行的,不过第二种比较慢
该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product