<?php
$params = require __DIR__ . '/params.php';
$db = require __DIR__ . '/db.php';
$config = [
'id' => 'basic',
//'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'basePath'=>dirname(__DIR__),
'bootstrap' => ['log'],
'language' => 'en', // default language
'sourceLanguage' => 'en', // source language (for translation purposes)
'aliases' => [
'@bower' => '@vendor/bower-asset',
'@npm' => '@vendor/npm-asset',
],
'components' => [
'session' => [
'class' => 'yii\web\Session',
'timeout' => 3600,
'cookieParams' => [
'httpOnly' => false,
'secure' => false, // Use only in production if you have HTTPS
// or 'Strict' for stricter cross-site handling
],
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'request' => [
'baseUrl' => '/myapp',
// !!! insert a secret key in the following (if it is empty) - this is required by cookie validation
// 'cookieValidationKey' => 'Mtm8EYpyJvSak9kEM2tOkJ9kSl9bNnxO',
],
'errorHandler' => [
'class' => 'yii\web\ErrorHandler',
// Optionally, you can configure the error action here (default is "site/error").
// 'errorAction' => 'site/error',
],
'request'=>[
'enableCookieValidation'=>false,
'enableCsrfValidation'=> false,
/* 'cookieValidationKey'=>'d2b09758796634802b4386138e3fc1e09c596eb66e2f478808da44e42b30da2c',*/
],
'i18n' => [
'translations' => [
'main*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages', // Directory where translation files are stored
'fileMap' => [
'main' => 'main.php', // This maps the 'app' category to the
],
],
'messages*' => [
'class' => 'yii\i18n\PhpMessageSource',
'basePath' => '@app/messages', // Directory where translation files are stored
'fileMap' => [
'messages' => 'messages.php', // This maps the 'app' category
],
],
],
],
'cache' => [
'class' => 'yii\caching\FileCache',
],
'user' => [
'identityClass' => 'app\models\User',
'enableAutoLogin' => true,
],
'errorHandler' => [
'errorAction' => 'site/error',
],
'mailer' => [
'class' => \yii\symfonymailer\Mailer::class,
'viewPath' => '@app/mail',
// send all mails to a file by default.
'useFileTransport' => true,
],
'log' => [
'traceLevel' => YII_DEBUG ? 3 : 0,
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
],
],
],
'db' => $db,
'session' => [
'class' => 'yii\web\DbSession',
'db' => $db, // This refers to the database connection component
'sessionTable' => 'session', // The name of the session table
],
'log' => [
'targets' => [
[
'class' => 'yii\log\FileTarget',
'levels' => ['error', 'warning'],
'logFile' => '@app/runtime/logs/app.log',
],
],
],
'urlManager' => [
'enablePrettyUrl' => true,
'showScriptName' => false,
'rules' => [
'lang/<language:\w{2}>/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
// Default route with language prefix
'lang/<language:\w{2}>/<controller:\w+>' => '<controller>/index',
'lang/<language:\w{2}>/<controller>' => '<controller>/index',
// Catch-all route for default without 'lang'
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
],
'CustomUrlManager' => [
'class' => 'app\components\CustomUrlManager',
'rules' => [
'lang/<language:\w{2}>/<controller:\w+>/<action:\w+>' => '<controller>/<action>',
// Default route with language prefix
'lang/<language:\w{2}>/<controller:\w+>' => '<controller>/index',
'lang/<language:\w{2}>/<controller>' => '<controller>/index',
// Catch-all route for default without 'lang'
'<controller:\w+>/<action:\w+>' => '<controller>/<action>',
],
// Any other custom settings for the UrlManager
],
],
'defaultRoute' => 'site/login',
'on beforeRequest' => function ($event) {
// Check if the 'lang' query parameter exists
$lang = Yii::$app->request->get('lang');
if ($lang && in_array($lang, ['de', 'en', 'fr'])) { // Supported languages
Yii::$app->language = $lang; // Set the application language dynamically
} else {
Yii::$app->language = 'en'; // Default language if no lang query parameter is set
}
},
'params' => $params,
];