您的位置:首页 > 编程语言 > PHP开发

yii2-datepicker/datetimepicker插件使用

2015-07-01 19:01 841 查看
datepicker:

https://github.com/2amigos/yii2-date-picker-widget

通过composer安装:

composer require 2amigos/yii2-date-picker-widget:~1.0


使用方法:

<?php
use dosamigos\datepicker\DatePicker;

// 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; width: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 dosamigos\datetimepicker\DateTimePicker;
// 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 dosamigos\datetimepicker\DateTimePicker;
?>
<?= $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
]
]);?>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息