silentlun/yii2-datepicker

Datepicker extension for YII2

Installs: 20

Dependents: 0

Suggesters: 0

Security: 0

Stars: 0

Watchers: 1

Forks: 0

Open Issues: 0

Type:yii2-extension

1.1 2021-09-18 02:50 UTC

This package is not auto-updated.

Last update: 2025-06-07 23:54:12 UTC


README

Datepicker extension for YII2

Installation

The preferred way to install this extension is through composer.

Either run

php composer.phar require --prefer-dist silentlun/yii2-datepicker "*"

or add

"silentlun/yii2-datepicker": "*"

to the require section of your composer.json file.

Usage

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

与表格一起使用的示例 有两种使用方式,一种是使用ActiveForm实例,另一种是使用小部件来设置其model和attribute。

<?php
use silentlun\datepicker\DatePicker;

// as a widget
?>

<?= DatePicker::widget([
    'model' => $model,
    'attribute' => 'date',
    'template' => '{addon}{input}',
        'pluginOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-mm-dd hh:ii'
        ]
]);?>

<?php 
// with an ActiveForm instance 
?>
<?= $form->field($model, 'date')->widget(
    DatePicker::className(), [
        // inline too, not bad
         'inline' => true, 
         // 自定义模板
        'template' => '<div style="background-color: #fff; width:250px">{input}</div>',
        'pluginOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-mm-dd hh:ii'
        ]
]);?>

没有模型的使用示例

<?php
use silentlun\datepicker\DatePicker;
?>
<?= DatePicker::widget([
    'name' => 'Test',
    'value' => '2021-03-21',
    'template' => '{addon}{input}',
        'pluginOptions' => [
            'autoclose' => true,
            'format' => 'yyyy-mm-dd hh:ii'
        ]
]);?>