金叶网/yii2-date-range

yii2-date-range

安装次数: 3

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 3

分支: 0

开放问题: 0

类型:yii2-extension

v0.1 2019-05-09 01:33 UTC

This package is auto-updated.

Last update: 2024-09-09 14:37:24 UTC


README

yii2-date-range

安装

安装此扩展的首选方式是通过 composer

运行以下命令之一:

php composer.phar require --prefer-dist xinyeweb/yii2-date-range "*"

或将以下内容添加到您的 composer.json 文件的 require 部分中:

"xinyeweb/yii2-date-range": "*"

to the require section of your composer.json file.

用法

一旦安装了扩展,只需在您的代码中通过以下方式使用它:

<?php 
//普通Input
echo \xinyeweb\daterange\DateRangePicker::widget([
                'name' => 'addDate',
                'locale' => 'zh-CN',
                'value' => $addDate,
                'template' => '
                    <div class="input-group">
                        <span class="input-group-addon">
                            <span class="glyphicon glyphicon-calendar"></span>
                         </span>
                        {input}
                    </div>
                ',
                'callback' => 'function() { }'
            ]);
<?php
//controller
$addDate = Yii::$app->request->get('addDate', '');
if (!empty($addDate)) {
    $addTime = explode('-', $addDate);
    $starttime = strtotime($addTime[0]);
    $endttime = strtotime($addTime[1])+86400;
    $query->andWhere(['>=', 'created_at', $starttime])
        ->andWhere(['<', 'created_at', $endttime]);
}
<?php
//Model
 echo DateRangePicker::widget([
     'model'     => $model,
     'attribute' => 'dateRange',
     
     // Optional. Used for calendar localization. 
     // IF `null` (default), default moment.js language will be used.
     'locale'    => 'ru-RU';
     // Daterange plugin options. Default is `null`.
     // See http://www.daterangepicker.com/#options
     'pluginOptions' => [
         /* ... */
         'autoUpdateInput' => false,
     ],
     // Optional. If maskOptions is set, MaskedInput will be used 
     // instead of TextInput. Default is `null`. 
     'maskOptions' => [
         'mask' => '99/99/9999 - 99/99/9999',
     ],
     // Optional. Input control options, 
     // default is `['class' => 'form-control']`.
     'options' => [
         /* ... */
     ],
     // Optional. Widget template, default is `{input}`. 
     // The special tag `{input}` will be replaced with the form input. 
     'template' => '
         <div class="input-group">
             <span class="input-group-addon">
                 <span class="glyphicon glyphicon-calendar"></span>
              </span>
             {input}
         </div>
     '
     ],
     // Optional. Javascript callback to be passed to the 
     // plugin constructor. By default, updates the input 
     // and triggers `change` event.
     'callback' => 'function() { /* ... */ }';   
     'pluginOptions' => [
          'ranges' => [
              'Today' => [date("Y/m/d", strtotime("today")), date("Y/m/d", strtotime("today"))],
              'Yesterday' => [date("Y/m/d", strtotime("-1 day")), date("Y-m-d", strtotime("-1 day"))],
              'Last 7 Days' => [date("Y/m/d", strtotime("-7 day")), date("Y/m/d", strtotime("today"))],
              'Last 30 Days' => [date("Y/m/d", strtotime("-30 day")), date("Y/m/d", strtotime("today"))],
              'This Month' => [date('Y/m/d', mktime(0, 0, 0, date('m'), '1', date('Y')))],
              'Last Month' => [ date('Y/m/01', strtotime('-1 month')), date("Y/m/t", strtotime('-1 month'))],
          ]
      ],
 ]);
 ?>```