Yii2 super easy to use date components and time components-White Wolf stack author: White Wolf Source: http://www.manks.top/yii2_datetimepicker.html this article copyright to the author, welcome to reprint, but without the author's consent must retain this statement, the original article connection is clearly provided on the article page, otherwise the right to pursue legal liability will be reserved. The original text contains images.
The date component is indispensable in normal development. Today, let's talk about the super-useful time components in yii2, which saves you a lot of effort to find js plug-ins.
Before sharing, let's preview the effect and see how it works.
Of course, the poor performance lies in the feeling of self. you cannot see the picture above. The good news is that these two plug-ins have been integrated with yii2, which is also very simple to use.
For the date component and the time component, the former is of the date ('Y-m-D') type, and the latter is of the date ('Y-m-d H: I: s') type ') type. Needless to say.
Let's take a look at the time component extension.
Since it is an extension component, the first step is to install it.
composer require kartik-v/yii2-widget-datetimepicker "*"
After the installation, if your form is generated using ActiveForm, you can refer to the following code
use kartik\datetime\DateTimePicker;
field($model, 'created_at')->widget(DateTimePicker::classname(), [ 'options' => ['placeholder' => ''], 'pluginOptions' => [ 'autoclose' => true, 'todayHighlight' => true, ] ]); ?>
Some users who do not like to use ActiveForm to generate forms need to refer to the following usage.
Use kartik \ datetime \ DateTimePicker; echo'Time'; Echo DateTimePicker: widget (['name' => 'Article [created_at]', 'options' => ['placeholder '=> ''], // note, when updating this method, you must specify the value 'value' => '2017-05-03 22:10:10 ', 'ininoptions' => ['autoclose' => true, 'format' => 'yyyy-mm-dd HH: ii: SS', 'todayhighlight' => true]);
The convenience is self-evident.
The entire installation process is really simple. next we will install the date component in the same way.
Continue reading