Difference between #109 and #110 of
Yii v2 snippet guide

Revision #110 has been created by rackycz on Sep 23, 2019, 12:25:46 PM with the memo:

typos
« previous (#109) next (#111) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
And your index.php should be here:

- C:\xampp\htdocs\basic\web\index.php

If you set thing
s correctly up, following URL will open your demo application. Now it will probably throw an exception: - [http://localhost/basic/web/](http://localhost/basic/web/) **The Exception is removed by enterinng any text into attribute 'cookieValidationKey' in file**:

- C:\xampp\htdocs\basic\config\web.php
[...]
- If a validator needs the method, it cannot be converted into JavaScript so the rule is checked only in the moment when user sends the form to the server - after successful JavaScript validation.

Now you can also create **CRUD** fo
tr the USser model using GII:

- [http://localhost/basic/web/index.php?r=gii](http://localhost/basic/web/index.php?r=gii).
[...]
*(Note that cs-CZ is for Czech Lanuage. For German you should use de-DE etc. Use any other language if you want.)*

The idea behind is that in the code ther
e are used only English texts and if you want to change from English to some other language this file will be used. Now go to file config/web.php, find section "components" and paste this codee i18n section:

```php
[...]
Explanation of the asterisk * can be found in article [https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n](https://www.yiiframework.com/doc/guide/2.0/en/tutorial-i18n)

You surely saw that in views and models there are
translated-texts saved like this:

```php
[...]
```

**Switching languages + session +
lang-dropdown in the top menu**
---
First lets add to file config/params.php attributes with list of supported languages:
[...]
```

Now in the top-right corner you can see a new drop-down-list with list of 2 languages. If one is selected, action "site/setLang" is
uscalled so we have to create it in SiteController.

*Note that this approach will always redirect user to the new action and his work will be lost. Nevertheless this approach is very simple so I am using it in small projects. More complex projects may require an ajax call when language is changed and then updating texts using javascript so reload is not needed and user's work is preserved. But I expect that when someone opens the web, he/she sets the language immediately and then there is no need for further changes.*
[...]
**Access rights**
---
... text ...

 
 
**Nice URLs**
 
---
 
... text ...
7 0
4 followers
Viewed: 254 368 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 5 months ago
Update Article

Revisions

View all history