/
Bootstrap.php
executable file
·97 lines (81 loc) · 3.69 KB
/
Bootstrap.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
namespace afzalroq\cms;
use kartik\datecontrol\Module;
use yii\base\BootstrapInterface;
use yii\web\Application;
class Bootstrap implements BootstrapInterface
{
public function bootstrap($app)
{
if (!isset($app->i18n->translations['cms']) && !isset($app->i18n->translations['cms*'])) {
$app->i18n->translations['cms'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
'sourceLanguage' => 'en',
'forceTranslation' => true,
];
}
if (!isset($app->i18n->translations['unit']) && !isset($app->i18n->translations['unit*'])) {
$app->i18n->translations['unit'] = [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => __DIR__ . '/messages',
'sourceLanguage' => 'en',
'forceTranslation' => true,
];
}
$app->bootstrap[] = 'cms';
$app->setModules([
'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:i:s',
Module::FORMAT_DATETIME => 'dd-MM-yyyy HH:i:s',
],
// 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:U',
],
// set your display timezone
'displayTimezone' => 'Asia/Tashkent',
// 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, 'todayBtn' => true]], // example
Module::FORMAT_DATETIME => ['pluginOptions' => ['autoclose' => true, 'todayBtn' => true]], // 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' => 'yii\jui\DatePicker', // example
'options' => [
'dateFormat' => 'php:d-M-Y',
'options' => ['class' => 'form-control'],
]
]
]
// other settings
]
]);
$app->on(Application::EVENT_BEFORE_REQUEST, [$this, 'addModuleUrlRules']);
}
public function addModuleUrlRules($event)
{
\Yii::$app->getUrlManager()->addRules([
'c/<c:[\w+-]+>' => 'c/collection',
'c/<c:[\w+-]+>/<o:[\w+-]+>' => 'c/option',
'e/<e:[\w+-]+>' => 'c/entity',
'e/<e:[\w+-]+>/<i:\d+>-<w:[\w+-]*>' => 'c/item',
]);
}
}