DateControl

Hello, I hope somebody could help me. What i wanted to do is display today date with format m-d-Y if it is a new record and if it’s an update action then display what already saved in the database.

Here is my web.php config:


'modules' => [

      'datecontrol' =>  [

          'class' => 'kartik\datecontrol\Module',


          // format settings for displaying each date attribute (ICU format example)

          'displaySettings' => [

              Module::FORMAT_DATE => 'dd-MM-yyyy',

              Module::FORMAT_TIME => 'HH:mm:ss a',

              Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:mm:ss a',

          ],


          // format settings for saving each date attribute (PHP format example)

          'saveSettings' => [

              Module::FORMAT_DATE => 'php:U', // saves as unix timestamp

              Module::FORMAT_TIME => 'php:H:i:s',

              Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',

          ],


          // set your display timezone

        //   'displayTimezone' => 'Asia/Kolkata',


          // set your timezone for date saved to db

          //'saveTimezone' => 'UTC',


          // automatically use kartik\widgets for each of the above formats

          'autoWidget' => true,


          // use ajax conversion for processing dates from display format to save format.

          'ajaxConversion' => true,


          // default settings for each widget from kartik\widgets used when autoWidget is true

          'autoWidgetSettings' => [


              Module::FORMAT_DATE => ['type'=>2, 'pluginOptions'=>['autoclose'=>true, 'todayHighlight' => true]], // example

              Module::FORMAT_DATETIME => [], // setup if needed

              Module::FORMAT_TIME => [], // setup if needed

          ],


          // custom widget settings that will be used to render the date input instead of kartik\widgets,

          // this will be used when autoWidget is set to false at module or widget level.

          'widgetSettings' => [

              Module::FORMAT_DATE => [


                  'class' => 'kartik\widgets\DatePicker', // example

                  'options' => [

                      'dateFormat' => 'php:d-M-Y',

                      'options' => ['class'=>'form-control'],

                  ]

              ]

          ]

          // other settings

    ],

and here is my params.php


<?php

use \kartik\datecontrol\Module;

Yii::setAlias('@applicationicons', realpath(dirname(__FILE__).'/../web/img/applicationicons'));

return [

    'adminEmail' => 'admin@example.com',

    'dateControlDisplay' => [

        Module::FORMAT_DATE => 'dd-MM-yyyy',

        Module::FORMAT_TIME => 'hh:mm:ss a',

        Module::FORMAT_DATETIME => 'dd-MM-yyyy hh:mm:ss a',

    ],


    // format settings for saving each date attribute (PHP format example)

    'dateControlSave' => [

        Module::FORMAT_DATE => 'php:U', // saves as unix timestamp

        Module::FORMAT_TIME => 'php:H:i:s',

        Module::FORMAT_DATETIME => 'php:Y-m-d H:i:s',

    ]

];



here is my _form.php


<?php echo $form->field($model, 'C1')->widget(DateControl::classname(), [

                    'name' => 'datecontrol',

                    'type' => DateControl::FORMAT_DATE,

                    'value' => date('Y-m-d'),

                    'displayFormat' => 'php:m-d-Y',

                    'saveFormat' => 'php:Y-m-d'

                    ]) ?>



It does work when i update which displays the date saved from database. It doesn’t display anything if it’s a new record. I can pick a date and it will display, but i want it to default to today’s date if possible?

Thanks a million. I’ve tried many different ways and i couldn’t get it work.