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

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

2016-01-09 11:17 901 查看

最近在学习yii2 框架,发现框架很强大,而且结合了时下许多新的技术在里面。

简单记录一下yii2-date-picker插件的使用方法:

首先先了解一下github中的相关资源:https://github.com/2amigos/yii2-date-picker-widget

其次:在自己的项目中利用上面链接中的相关方法下载此资源,命令为:

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

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

use dosamigos\datepicker\DatePicker;

例子中提供了两种方法:

方法1. 使用widget方式

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

方法2. ActiveForm方式

<?= $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'
]
]);?>

希望本文所述对大家基于Yii框架的PHP程序设计有所帮助。

您可能感兴趣的文章:

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  Yii2 日期 插件