silentlun / yii2-datepicker
YII2 的日期选择器扩展
1.1
2021-09-18 02:50 UTC
Requires
- yiisoft/yii2: ~2.0.0
This package is not auto-updated.
Last update: 2024-09-28 20:30:35 UTC
README
YII2 的日期选择器扩展
安装
安装此扩展的首选方式是通过 composer。
运行以下命令之一
php composer.phar require --prefer-dist silentlun/yii2-datepicker "*"
或在您的 composer.json 文件的 require 部分添加
"silentlun/yii2-datepicker": "*"
。
用法
扩展安装完成后,只需在代码中使用它即可
与表格一起使用的示例 有两种使用方式,一种是使用 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' ] ]);?>