S
S
Sandro_s2017-08-24 13:48:17
Yii
Sandro_s, 2017-08-24 13:48:17

How to properly set date and time widgets in Yii2?

The site has the following structure: in site - public (admin, assets, uploads) and yii2 - fronted and backend. Vendor has a blog as a separate module. The folder ' time' (created without CRUD) is in dir: yii2\ backend\views\time 82c5237fafc0459e9cd4092850106004.jpgf5549314074240eaaf96b8121f86b64e.jpgcd1e6fa5b1c44587bd3e58bf73b51ea4.jpg
When I try to generate CRUD, I get this error: 3ff5f17fc06248aaabe613ccc9f96ff0.jpg
yii2\backend\config\main.php

<?php
use \kartik\datecontrol\Module;
$params = array_merge(
    require(__DIR__ . '/../../common/config/params.php'),
    require(__DIR__ . '/../../common/config/params-local.php'),
    require(__DIR__ . '/params.php'),
    require(__DIR__ . '/params-local.php')
);

return [
    'id' => 'app-backend',
    'basePath' => dirname(__DIR__),
    'controllerNamespace' => 'backend\controllers',
    'bootstrap' => ['log','gii','debug'],
    'language' => 'ru',
    'modules'=>[
    'gii'=>[
    'class'=>'yii2\gii\Module',
     'generators' => [ //here
            'crud' => [ // generator name
                'class' => 'yii\gii\generators\crud\Generator', // generator class
                'templates' => [ //setting for out templates
                    'myGii' => '@common/generators/crud/default', // template name => path to template
                ]
            ]
        ],
    ],
    'debug'=>[
    'class'=>'yii2\debug\Module'
    ],
   'blog' => [
            'class' => 'sand\blog\Blog',
        ],
     'datecontrol'=> [
     'class'=> 'kartik\datecontrol\Module',
      // format settings for displaying each date attribute (ICU format example)
'displaySettings' => [
    Module::FORMAT_DATE => 'php:d-M-Y', 
    /*'dd-MM-yyyy',*/
    Module::FORMAT_TIME => 'php: H:1',
    /*'hh:mm:ss a',*/
    Module::FORMAT_DATETIME => 'php:d-m-Y H:1',
    /*'dd-MM-yyyy hh:mm:ss a',*/ 
],
 
// format settings for saving each date attribute (PHP format example)
'saveSettings' => [
    Module::FORMAT_DATE => 'yyyy-M-dd', 
    /*'php:U', // saves as unix timestamp*/
    Module::FORMAT_TIME => 'H:i:s',
    /*'php:H:i:s',*/
    Module::FORMAT_DATETIME => 'yyyy-M-dd H:i:s',
    /*'php:Y-m-d H:i:s',*/
],   
'displayTimezone'=>'UTC',
'saveTimezone' => 'UTC',
'autoWidget' =>true,
]
    ],
       
    'components' => [
    /* 'view' => [
         'theme' => [
             'pathMap' => [
                '@app/views' => '@vendor/dmstr/yii2-adminlte-asset/example-views/yiisoft/yii2-app'
             ],
         ],
    ],*/
        'request' => [
            'csrfParam' => '_csrf-backend',
        ],
        'user' => [
            'identityClass' => 'common\models\User',
            'enableAutoLogin' => true,
            'identityCookie' => ['name' => '_identity-backend', 'httpOnly' => true],
        ],
       
         'session' => [
            // this is the name of the session cookie used for login on the backend
            'name' => 'advanced-backend',
        ],
        
        'log' => [
            'traceLevel' => YII_DEBUG ? 3 : 0,
            'targets' => [
                [
                    'class' => 'yii\log\FileTarget',
                    'levels' => ['error', 'warning'],
                ],
            ],
        ],
        'errorHandler' => [
            'errorAction' => 'site/error',
        ],
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,


            'rules' => [
            

            ],
        ],
       'formatter'=> [
            'class' =>'yii\i18n\Formatter',
           /*  'defaultTimeZone' => 'Europe/Samara',*/
            /* 'timeZone' => 'GMT+5',*/
            'decimalSeparator' => ',',
            'thousandSeparator' => ' ',
            'currencyCode' => 'EUR',
           /* 'dateFormat' => 'd MMMM yyyy',*/
            'dateFormat' => 'php:d-M-Y',
            'datetimeFormat' => 'php: d-M-Y H:i:',

            /*'datetimeFormat'=>'d-M-Y H:i:s',*/
           /* 'timeFormat' => 'H:i:s', */
    ],

],
    'params' => $params,
];

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
Maxim Fedorov, 2017-08-24
@Maksclub

First, create a Time model in gii, then do CRUD for it
because you refer to it, but it is not in the common / models folder
CRUD is essentially a set of controllers and views, well, an optional search model

M
Maxim Timofeev, 2017-08-24
@webinar

It could have been just a mistake. She clearly describes the problem.
You are generating CRUD based on the common/models/Time model and it doesn't exist. So first you need to generate the common/models/Time model in the same place in gii

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question