问题
I want to use yii2 datepicker but I'm having trouble to implement this. It does not show the date picker and I don't know what is missing in my code. I'm still new in this yii
<?php
use yii\helpers\Html;
use yii\bootstrap\ActiveForm;
?>
<div class="row">
<div class="col-lg-6">
<div class="myproj-index">
<?php $form = ActiveForm::begin(['layout' => 'horizontal']); ?>
<? //$form->field($model, 'periodfrom')
echo DatePicker::widget([
'model' => $model,
'attribute' => 'periodfrom',
'language' => 'en',
'dateFormat' => 'yyyy-MM-dd',
]);
?>
<div class="form-group">
<?= Html::submitButton('Submit', ['class' => 'btn btn-primary']) ?>
</div>
<?php ActiveForm::end(); ?>
</div>
</div>
</div>
Edit
I downloaded this file here jui
I found out that in my file I have no jui folder under yiisoft folder. My question in appasset how can I declare this files ?
Answer
I fixed it, I downloaded the jquery-ui files then added them to the bower folder in yii2.
回答1:
First install this extension through composer.
- run:
php composer.phar require --prefer-dist yiisoft/yii2-jui "*"
in your project directory. - update composer.
- In your view file use
use yii\jui\DatePicker;
.
You probably did not install Datepicker in the vendor package. Thanks.
回答2:
Do you have use .....\DatePicker;
?
Also are you including the jui asset and everything, take a look at the source, do you have jui and all the JS included?
Edit: Have you done a "composer update" lately?
回答3:
Use this code if you are using kartik datetime picker
<?= $form->field($model, 'date')->widget(DatePicker::classname(),['options' => ['placeholder' => 'Enter event time ...'],'pluginOptions' => [....]]) ?>
来源:https://stackoverflow.com/questions/27330300/how-to-use-datepicker-in-yii2-basic