雖然非常喜歡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'
]
]);?>