Kartik-V DateControl

Hi,

i’m trying to build a form with Kartik Form Builder, but i’mstucked with the datecontrol and datepicker. Apparently I cannot save the date in the correct mysql format; it’s saved as 0000-00-00.

Following the instructions I get a php error [i]PHP Fatal error: Class ‘kartik\\datecontrol\\Module’ not found in /var/www/html/alex/config/params.php on line 9

[/i]

This is my params.php file


<?php

use kartik\datecontrol\Module;


return [

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


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

    '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',

    ]

];



on params.php

Generally I cannot fully understand where to put the code in yii… Maybe someone could give me a hint?

in frontend/config/main.php below


return [

/*datecontrol

'modules' => [

     

    'datecontrol' => [

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

          ],

       

    ],

];

in view file


use kartik\datecontrol\DateControl;

echo $form->field($model,'DOB')->widget(DatePicker::classname(),[


        'options' => ['placeholder' => 'Select DOB'],


        'pluginOptions' => [


            'format' => 'dd/mm/yyyy',


            'todayHighlight' => true,


            'autoclose'=>true,


             ]


        ]);

Thank you, now I can set format for saving, but I’m outside the Form Builder Form::widget…

Setup for save timestamp, dependency DateTimePicker:

ActiveForm


use kartik\datecontrol\DateControl; 

   <?= $form->field($model, 'time_stamp_add')->widget(DateControl::classname(), [

        'type' => DateControl::FORMAT_DATETIME,

        'ajaxConversion' => false,

        'displayFormat' => 'php:D, d-m-Y H:i:s',

        'saveFormat' => 'php:U',

        'options' => [

            'pluginOptions' => [

                'autoclose' => true

            ]

        ]

    ]) ?>

main.php


'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',

        ],

          ],

    ],

how if in basic case sir?