datepicker:
https://github.com/2amigos/yii2-date-picker-widget
通过composer安装:
composer require 2amigos/yii2-date-picker-widget:~1.0
使用方法:
<?php
use dosamigosdatepickerDatePicker;
// as a widget
?>
<?= DatePicker::widget([
'model' => $model,
'attribute' => 'date',
'template' => '{addon}{input}',
'clientOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);?>
<?php
// with an ActiveForm instance
?>
<?= $form->field($model, 'date')->widget(
DatePicker::className(), [
// inline too, not bad
'inline' => true,
// modify template for custom rendering
'template' => '<div class="well well-sm" style="background-color: #fff; 250px">{input}</div>',
'clientOptions' => [
'autoclose' => true,
'format' => 'dd-M-yyyy'
]
]);?>
datetimepicker:
http://www.yiiframework.com/extension/yii2-datetimepicker-widget/
通过composer安装:
php composer.phar require "2amigos/yii2-date-time-picker-widget" "*"
使用方法:
<?php
use dosamigosdatetimepickerDateTimePicker;
// as a widget
?>
<?= DateTimePicker::widget([
'model' => $model,
'attribute' => 'created_at',
'language' => 'es',
'size' => 'ms',
'clientOptions' => [
'autoclose' => true,
'format' => 'dd MM yyyy - HH:ii P',
'todayBtn' => true
]
]);?>
<?= DateTimePicker::widget([
'id' => 'test1',
'name' => 'test1',//当没有设置model时和attribute时必须设置name
'language' => 'es',
'size' => 'ms',
'clientOptions' => [
'autoclose' => true,
'format' => 'dd MM yyyy - HH:ii P',
'todayBtn' => true
]
]);?>
<?php
// with an ActiveForm instance displayed as a TimePicker
use dosamigosdatetimepickerDateTimePicker;
?>
<?= $form->field($tour, 'date_from')->widget(DateTimePicker::className(), [
'language' => 'es',
'size' => 'ms',
'template' => '{input}',
'pickButtonIcon' => 'glyphicon glyphicon-time',
'inline' => true,
'clientOptions' => [
'startView' => 1,
'minView' => 0,
'maxView' => 1,
'autoclose' => true,
'linkFormat' => 'HH:ii P', // if inline = true
// 'format' => 'HH:ii P', // if inline = false
'todayBtn' => true
]
]);?>
版权声明:本文为博主原创文章,未经博主允许不得转载。