yii2.0使用bootstrap中日期插件

Yii2框架引用bootstrap中日期插件yii2-date-picker的方法。

使用composer安装 日期插件

 php composer.phar require "2amigos/yii2-date-picker-widget" "*"

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

在视图文件中使用下面的代码 :

use dosamigos\datepicker\DatePicker;
<span>开始时间:</span>

//方法一:使用widget方式1

1 <?=DatePicker::widget([
2   'name' => 'jui-start-time', 
3   'template' => '{addon}{input}',
4   'clientOptions' => [
5     'autoclose' => true,
6     'format' => 'yyyy-mm-dd'
7   ]
8 ]);?>

//方法二:使用widget方式2

1 <?= DatePicker::widget([
2   'model' => $model,
3   'attribute' => 'date',
4   'template' => '{addon}{input}',
5   'clientOptions' => [
6     'autoclose' => true,
7     'format' => 'yyyy-mm-dd'
8   ]
9 ]);?>

//方法三:ActiveForm方式

 1 <?= $form->field($model, 'date')->widget(
 2   DatePicker::className(), [
 3   // inline too, not bad
 4   'inline' => true, 
 5   // modify template for custom rendering
 6   'template' => '<div class="well well-sm" style="background-color: #fff; width:250px">{input}</div>',
 7   'clientOptions' => [
 8     'autoclose' => true,
 9     'format' => 'yyyy-mm-dd'
10   ]
11 ]);?>

 

 

 显示:

 

参考:http://www.qianbo.com.cn/Study/Program/60054.html

二、使用yii2自带的插件

1 <?=\yii\jui\DatePicker::widget([
2     'name' => 'Staff[birthday]',
3     'value' => $model->birthday,
4     'dateFormat' => 'yyyy-MM-dd',
5     'options' => ['placeholder'=>'出生日期', 'class'=>'form-control']
6 ]) ?>

 

 

posted @ 2017-08-16 14:53  py卡卡  阅读(367)  评论(0编辑  收藏  举报