定制 nkovacs/yii2-datetimepicker 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

nkovacs/yii2-datetimepicker

最新稳定版本:3.1.1

Composer 安装命令:

composer require nkovacs/yii2-datetimepicker

包简介

Bootstrap datetimepicker widget for Yii 2, based on Eonasdan/bootstrap-datetimepicker.

README 文档

README

Bootstrap datetimepicker widget for Yii 2, based on Eonasdan/bootstrap-datetimepicker.

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist nkovacs/yii2-datetimepicker "*"

or add

"nkovacs/yii2-datetimepicker": "*"

to the require section of your composer.json file.

Usage

Once the extension is installed, simply use it in your code:

<?= \nkovacs\datetimepicker\DateTimePicker::widget([
    'name' => 'time',
]); ?>

or as an active field:

<?= $form->field($model, 'time')->widget(\nkovacs\datetimepicker\DateTimePicker::className(), [
    'clientOptions' => [
        'extraFormats' => ['YYYY-MM-DD HH:mm'],
    ],
]) ?>

To show just a datepicker:

<?= $form->field($model, 'time')->widget(\nkovacs\datetimepicker\DateTimePicker::className(), [
    'type' => 'date',
]) ?>

or just a timepicker:

<?= $form->field($model, 'time')->widget(\nkovacs\datetimepicker\DateTimePicker::className(), [
    'type' => 'time',
]) ?>

The widget will load the moment locale file for Yii::$app->language if it can find it.

It will also use Yii::$app->formatter->dateFormat, Yii::$app->formatter->timeFormat or Yii::$app->formatter->datetimeFormat depending on type.

Use the timestampAttribute property of the validator in this extension to get the parsed timestamp.

Both can be overriden using the locale and format options.

Validators

The extension comes with an improved datetime validator. Yii's default DateValidator cannot handle time values with the default ICU 'medium' format. The validator adds a type option that specifies what kind of value should be accepted: date, time or datetime.

To register the validator, add the following line to your app config file:

\nkovacs\datetimepicker\DateTimeValidator::register();

This replaces the built-in date validator and adds a time and datetime validator:

    ...
    ['timestamp', 'datetime'],
    ['time', 'time'],
    ['date', 'date'],
    ...

统计信息

  • 总下载量: 61.44k
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 10
  • 点击次数: 1
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 10
  • Watchers: 1
  • Forks: 6
  • 开发语言: PHP

其他信息

  • 授权协议: BSD-3-Clause
  • 更新时间: 2014-07-28