目录
回复讨论(解决方案)
首页 后端开发 php教程 YII 按照日期过滤不起作用,怎么回事?

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

Jun 23, 2016 pm 02:13 PM

Yii PHP 日期过滤

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

模型

<?php/** * This is the model class for table "user". * * The followings are the available columns in table 'user': * @property integer $id * @property string $uname */class Timefliter extends CActiveRecord{	/**	 * Returns the static model of the specified AR class.	 * @param string $className active record class name.	 * @return User the static model class	 */	public static function model($className=__CLASS__)	{		return parent::model($className);	}	/**	 * @return string the associated database table name	 */	public function tableName()	{		return 't_time';	}		public $starttime;	public $endtime;   				/**	 * @return array validation rules for model attributes.	 */	public function rules()	{		// NOTE: you should only define rules for those attributes that		// will receive user inputs.		return array(			array('id', 'safe'),			//array('id', 'numerical', 'integerOnly'=>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','<='.$this->endtime);		//是否开启模糊搜索,在后面true中实现		return new CActiveDataProvider($this, array(			'criteria'=>$criteria,		    			//'pagination'=>array('pagesize'=>$pagesize?pagesize:$page),		    //'pagination'=>array('pagesize'=>$page),		));	}}
登录后复制




视图
<form method="post" ><!--时间查询-->开始时间<?php     $this->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?> 结束时间<?php     $this->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,             ),     )); ?> <!--$criteria->compare('create_time','<='.$this->endtime),//创建早间小于等于指定时间  这个名字name就是widget里面的name的数据库字段,将它放到搜索页面中指定前端名字,和后端数据库的字段在模型module里面指定compare的条件即可实现时间搜索-->	<input type="submit"  name="search" value="搜索"/></form>
登录后复制



控制器

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


回复讨论(解决方案)

提交之后又没把获取的日期值赋值给模型,那在search方法中怎么会过滤

怎么复制给模型

可以用另外一种解决方案,自己新建一个dataprovinder 然后sql语句查询时间之间的记录

$model->startTime=$_POST['starttime'];    //传值给模型$model->endTime=$_POST['endtime'];  
登录后复制


谢谢楼上两位,都搞定了,两种方法都是可行的,不过第二种比较慢
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn

热AI工具

Undresser.AI Undress

Undresser.AI Undress

人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover

AI Clothes Remover

用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

AI Hentai Generator

AI Hentai Generator

免费生成ai无尽的。

热门文章

R.E.P.O.能量晶体解释及其做什么(黄色晶体)
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.最佳图形设置
3 周前 By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O.如果您听不到任何人,如何修复音频
3 周前 By 尊渡假赌尊渡假赌尊渡假赌

热工具

记事本++7.3.1

记事本++7.3.1

好用且免费的代码编辑器

SublimeText3汉化版

SublimeText3汉化版

中文版,非常好用

禅工作室 13.0.1

禅工作室 13.0.1

功能强大的PHP集成开发环境

Dreamweaver CS6

Dreamweaver CS6

视觉化网页开发工具

SublimeText3 Mac版

SublimeText3 Mac版

神级代码编辑软件(SublimeText3)

PHP记录:PHP日志分析的最佳实践 PHP记录:PHP日志分析的最佳实践 Mar 10, 2025 pm 02:32 PM

PHP日志记录对于监视和调试Web应用程序以及捕获关键事件,错误和运行时行为至关重要。它为系统性能提供了宝贵的见解,有助于识别问题并支持更快的故障排除

在Laravel中使用Flash会话数据 在Laravel中使用Flash会话数据 Mar 12, 2025 pm 05:08 PM

Laravel使用其直观的闪存方法简化了处理临时会话数据。这非常适合在您的应用程序中显示简短的消息,警报或通知。 默认情况下,数据仅针对后续请求: $请求 -

php中的卷曲:如何在REST API中使用PHP卷曲扩展 php中的卷曲:如何在REST API中使用PHP卷曲扩展 Mar 14, 2025 am 11:42 AM

PHP客户端URL(curl)扩展是开发人员的强大工具,可以与远程服务器和REST API无缝交互。通过利用Libcurl(备受尊敬的多协议文件传输库),PHP curl促进了有效的执行

简化的HTTP响应在Laravel测试中模拟了 简化的HTTP响应在Laravel测试中模拟了 Mar 12, 2025 pm 05:09 PM

Laravel 提供简洁的 HTTP 响应模拟语法,简化了 HTTP 交互测试。这种方法显着减少了代码冗余,同时使您的测试模拟更直观。 基本实现提供了多种响应类型快捷方式: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

在Codecanyon上的12个最佳PHP聊天脚本 在Codecanyon上的12个最佳PHP聊天脚本 Mar 13, 2025 pm 12:08 PM

您是否想为客户最紧迫的问题提供实时的即时解决方案? 实时聊天使您可以与客户进行实时对话,并立即解决他们的问题。它允许您为您的自定义提供更快的服务

解释PHP中晚期静态结合的概念。 解释PHP中晚期静态结合的概念。 Mar 21, 2025 pm 01:33 PM

文章讨论了PHP 5.3中引入的PHP中的晚期静态结合(LSB),从而允许静态方法的运行时分辨率调用以获得更灵活的继承。 LSB的实用应用和潜在的触摸

自定义/扩展框架:如何添加自定义功能。 自定义/扩展框架:如何添加自定义功能。 Mar 28, 2025 pm 05:12 PM

本文讨论了将自定义功能添加到框架上,专注于理解体系结构,识别扩展点以及集成和调试的最佳实践。

See all articles