How to use datepicker in yii2 basic?

拟墨画扇 提交于 2019-12-23 06:50:07

问题


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.

  1. run: php composer.phar require --prefer-dist yiisoft/yii2-jui "*" in your project directory.
  2. update composer.
  3. 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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!