Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use datepicker in yii2 basic?

Tags:

yii2

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.

like image 456
ashTon Avatar asked Dec 06 '14 09:12

ashTon


1 Answers

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.

like image 140
Rabib Avatar answered Sep 28 '22 08:09

Rabib