YII の日付によるフィルタリングが機能しません。何が起こっていますか?
Yii PHP 日付フィルタリング
YII 日付によるフィルタリングが機能しません。何が起こっていますか?Model
<?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), )); }}
View
<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>
Controller
public function actionTimefliter() { $model=new Timefliter(); $this->render('timefliter',array('model'=>$model,)); }
送信後、取得された日付値はにあるモデルに割り当てられています。検索方法 フィルターする方法
モデルにコピーする方法
別のソリューションを使用して、自分で新しいデータプロバイダーを作成し、SQL ステートメントでレコードをクエリすることもできます
$model->startTime=$_POST['starttime']; //传值给模型$model->endTime=$_POST['endtime'];
上の 2 人に感謝します。解決しました。2 つの方法どちらも実行可能ですが、2 番目の方法は時間がかかります

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

メモ帳++7.3.1
使いやすく無料のコードエディター

SublimeText3 中国語版
中国語版、とても使いやすい

ゼンドスタジオ 13.0.1
強力な PHP 統合開発環境

ドリームウィーバー CS6
ビジュアル Web 開発ツール

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

ホットトピック











多くの場合、キーワードと追跡パラメーターで散らかった長いURLは、訪問者を阻止できます。 URL短縮スクリプトはソリューションを提供し、ソーシャルメディアやその他のプラットフォームに最適な簡潔なリンクを作成します。 これらのスクリプトは、個々のWebサイトにとって価値があります

2012年のFacebookによる有名な買収に続いて、Instagramはサードパーティの使用のために2セットのAPIを採用しました。これらはInstagramグラフAPIとInstagram Basic Display APIです。

Laravelは、直感的なフラッシュメソッドを使用して、一時的なセッションデータの処理を簡素化します。これは、アプリケーション内に簡単なメッセージ、アラート、または通知を表示するのに最適です。 データは、デフォルトで次の要求のためにのみ持続します。 $リクエスト -

これは、LaravelバックエンドとのReactアプリケーションの構築に関するシリーズの2番目と最終部分です。シリーズの最初の部分では、基本的な製品上場アプリケーションのためにLaravelを使用してRESTFUL APIを作成しました。このチュートリアルでは、開発者になります

Laravelは簡潔なHTTP応答シミュレーション構文を提供し、HTTP相互作用テストを簡素化します。このアプローチは、テストシミュレーションをより直感的にしながら、コード冗長性を大幅に削減します。 基本的な実装は、さまざまな応答タイプのショートカットを提供します。 Illuminate \ support \ facades \ httpを使用します。 http :: fake([[ 'google.com' => 'hello world'、 'github.com' => ['foo' => 'bar']、 'forge.laravel.com' =>

PHPクライアントURL(CURL)拡張機能は、開発者にとって強力なツールであり、リモートサーバーやREST APIとのシームレスな対話を可能にします。尊敬されるマルチプロトコルファイル転送ライブラリであるLibcurlを活用することにより、PHP Curlは効率的なexecuを促進します

顧客の最も差し迫った問題にリアルタイムでインスタントソリューションを提供したいですか? ライブチャットを使用すると、顧客とのリアルタイムな会話を行い、すぐに問題を解決できます。それはあなたがあなたのカスタムにより速いサービスを提供することを可能にします

2025 PHP Landscape Surveyは、現在のPHP開発動向を調査しています。 開発者や企業に洞察を提供することを目的とした、フレームワークの使用、展開方法、および課題を調査します。 この調査では、現代のPHP Versioの成長が予想されています
