Home > Article > Backend Development > The Yii2 framework refers to the method of the date plug-in yii2-date-picker in bootstrap, yii2datepicker_PHP tutorial
The example in this article describes the method of the Yii2 framework to refer to the date plug-in yii2-date-picker in bootstrap. Share it with everyone for your reference, the details are as follows:
I have been learning the yii2 framework recently and found that the framework is very powerful and incorporates many new technologies nowadays.
Briefly record how to use the yii2-date-picker plug-in:
First, take a look at the relevant resources in github: https://github.com/2amigos/yii2-date-picker-widget
Second: Use the relevant method in the link above to download this resource in your own project, the command is:
php composer.phar require "2amigos/yii2-date-picker-widget" "*"
Finally, use the following code in your view file:
use dosamigosdatepickerDatePicker;
The example provides two methods:
Method 1. Use widget method
<?= DatePicker::widget([ 'model' => $model, 'attribute' => 'date', 'template' => '{addon}{input}', 'clientOptions' => [ 'autoclose' => true, 'format' => 'dd-M-yyyy' ] ]);?>
Method 2. ActiveForm method
<?= $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' ] ]);?>
I hope this article will be helpful to everyone’s PHP program design based on the Yii framework.