Heim  >  Artikel  >  php教程  >  Yii2框架引用bootstrap中日期插件yii2-date-picker的方法,yii2datepicker

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

WBOY
WBOYOriginal
2016-06-13 08:47:551521Durchsuche

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

本文实例讲述了Yii2框架引用bootstrap中日期插件yii2-date-picker的方法。分享给大家供大家参考,具体如下:

最近在学习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方式

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

方法2. ActiveForm方式

<&#63;= $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'
    ]
]);&#63;>

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

您可能感兴趣的文章:

  • Yii2使用Bootbox插件实现自定义弹窗
  • 从零开始学YII2框架(四)扩展插件yii2-kartikgii
  • 从零开始学YII2框架(三)扩展插件yii2-gird
  • 从零开始学YII2框架(二)通过 Composer 安装扩展插件
  • yii2框架中使用下拉菜单的自动搜索yii-widget-select2实例分析
  • yii2中使用Active Record模式的方法
  • YII2.0之Activeform表单组件用法实例
  • yii2中添加验证码的实现方法
Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn