作者:白狼 出处:http://www.manks.top/yii2_datetimepicker.html 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。原文有图片。
日期组件,时间组件在平时开发中是必不可少的。今天我们就来谈谈在yii2中的超好用的时间组件,也省的大家各种找js插件了。
分享之前我们先预览下效果,看看到底怎么个好用法。
当然啦,好用不好用在于自我的感觉,光看上面的图片是感受不到的。再告诉你个好消息,这两款插件已经跟yii2整合了,使用起来也是灰常的简单哦。
关于日期组件跟时间组件,前者是date('Y-m-d')类型,后者是date('Y-m-d H:i:s')类型,自然不用多说。
我们先来看看时间组件扩展
既然是扩展组建,第一步当然是安装。
composer <span style="color: #0000ff;">require</span> kartik-v/yii2-widget-datetimepicker "*"
安装好之后,如果你的表单使用ActiveForm生成的,可以参考下面的代码
<span style="color: #0000ff;">use</span><span style="color: #000000;"> kartik\datetime\DateTimePicker; </span>= <span style="color: #800080;">$form</span>->field(<span style="color: #800080;">$model</span>, 'created_at')->widget(DateTimePicker::classname(),<span style="color: #000000;"> [ </span>'options' => ['placeholder' => ''], 'pluginOptions' =><span style="color: #000000;"> [ </span>'autoclose' => <span style="color: #0000ff;">true</span>, 'todayHighlight' => <span style="color: #0000ff;">true</span>,<span style="color: #000000;"> ] ]); </span>?>
有些不喜欢用ActiveForm生成表单的同学就需要参考下面的用法了
<span style="color: #0000ff;">use</span><span style="color: #000000;"> kartik\datetime\DateTimePicker; </span><span style="color: #0000ff;">echo</span> '<label>时间</label>'<span style="color: #000000;">; </span><span style="color: #0000ff;">echo</span> DateTimePicker::<span style="color: #000000;">widget([ </span>'name' => 'Article[created_at]', 'options' => ['placeholder' => ''], <span style="color: #008000;">//</span><span style="color: #008000;">注意,该方法更新的时候你需要指定value值 </span> 'value' => '2016-05-03 22:10:10', 'pluginOptions' =><span style="color: #000000;"> [ </span>'autoclose' => <span style="color: #0000ff;">true</span>, 'format' => 'yyyy-mm-dd HH:ii:ss', 'todayHighlight' => <span style="color: #0000ff;">true</span><span style="color: #000000;"> ] ]);</span>
至于哪个方便,不言而喻。
整个安装过程确实很简单,我们接下来以同样的方式进行安装日期组件。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft
