Revision #71 has been created by rackycz on Sep 20, 2019, 2:58:47 PM with the memo:
edit
« previous (#70) next (#72) »
Changes
Title
unchanged
Yii v2 for beginners
Category
unchanged
Tutorials
Yii version
unchanged
2.0
Tags
unchanged
tutorial,beginner,yii2
Content
changed
[...]
// ... other configs
```
Switching languages + session + dropdown in the top menu
---
First lets add to file config/web.php one moreparams.php attribute
s with list of supported languages:
```php
aa
// config/web.php
$config = [
// use your language
// also accessible via Yii::$app->language
'language' => 'cs-CZ'
<?php
return [
// ...
'allowedLanguages' => [
'en-US' => "English",
'cs-CZ' => "Česky",
],
// This attribut'langSwitchUrl' => '/site/set-lang',
];
```
This list can be
dis
not necessary.
// en-US is default value
'sourceLanguage' => 'en-US',
played in the main menu. Edit file:
- C:\xampp\htdocs\basic\views\layouts\main.php
And above the Nav::widget add few rows:
```php
$listOfLanguages = [];
$langSwitchUrl = Yii::$app->params["langSwitchUrl"];
foreach (Yii::$app->params["allowedLanguages"] as $langId => $langName) {
'allowedLanguages' => ['en-US', 'cs-CZ'], $listOfLanguages[] = ['label' => Yii::t('app', $langName), 'url' => [$langSwitchUrl, 'langID' => $langId]];
}
// ... other configs```
and then add one item into Nav::widge
```php
echo Nav::widget([
// ...
'items' => [
// ...
['label' => Yii::t('app', 'Language'),'items' => $listOfLanguages],
// ...
```
Access rights
---
... text ...