虽然非常喜欢YII2快速开发,但是原生表单Active form的不可控,让我很不喜欢,也许有可控的方法,比如activeform提供input类型就很有限,没有这种日期框
这里引入github上的Yii2-date-picker插件
首先在你的项目文件下,使用composer下载
php composer.phar require "2amigos/yii2-date-picker-widget" "*"
在视图文件中引入
use dosamigos\datepicker\DatePicker;
在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'
]
]);?>