- When creating the model, check this checkbox: **Enable I18N** ... we will need i18n later
- Enter table name "user" and model name "User"
- Note that there already is a model named User in the demo app. You will not need it if you want to use login-via-DB so feel free to check the overwrite-checkbox in GII. The newly created User model will now be usable only for table operations, not for login. But we will enhance it, see the snippet below.
- The new model will onreplace existing model User with following snippet
- The model was generated by Gii and originally haved 3 methods: tableName(), rules(), attributeLabels()
- In order to use the DB for login, we needed to implement IdentityInterface which requires [5 new methods](https://www.yiiframework.com/doc/api/2.0/yii-web-identityinterface).
- Plus we add 2 methods because of the default LoginForm otherwise the web will not work.
- Once you use the snippet below, you can create CRUD for model User.
The final model should look like this:and 1 validator.
```php
[...]
```
Now you can also create Validators vs JavaScript:
- There are 2 types of validators. All of them are used in method **rules**, but as you can see, the validator **setPasswordWhenChanged** is my custom validator and needs a special method.
- If a validator does not need this special method, it is automatically converted into JavaScript and is used on the web page when you are typing.
- 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.
CRUD = Create Read Update Delete = views and controller. On the GII page enter following values:
- Model Class = app\models\User
- Search Model Class = app\models\UserSearch
- Controller Class = app\controllers\UserController
- View Path can be empty or you can set: views\user