Difference between #103 and #104 of
Yii v2 snippet guide

Revision #104 has been created by rackycz on Sep 21, 2019, 6:22:44 AM with the memo:

edit
« previous (#103) next (#105) »

Changes

Title unchanged

Yii v2 snippet guide

Category unchanged

Tutorials

Yii version unchanged

2.0

Tags unchanged

tutorial,beginner,yii2

Content changed

[...]
Then use GII to generate model. The GII URL will probably be
- [http://localhost/basic/web/index.php?r=gii](http://localhost/basic/web/index.php?r=gii).
- When creating the model, check this checkbox: **Enable I18N** ... we will need i18n later
- Enter table name "user" and model name "User"
- Do not create CRUD now, first replace the new User model with the code below.
 
 
- 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 only have 3 methods: tableName(), rules(), attributeLabels() - In order to use the DB for login, we need to implement IdentityInterface which requires [5 new methods](https://www.yiiframework.com/doc/api/2.0/yii-web-identityinterface). But as I do not need all those methods, in some of them I have commented out their body in the example below.
 
- Plus we add 2 methods because of the default LoginForm

 
- 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:

```php
<?php
[...]
7 0
4 followers
Viewed: 258 018 times
Version: 2.0
Category: Tutorials
Written by: rackycz
Last updated by: rackycz
Created on: Sep 19, 2019
Last updated: 6 months ago
Update Article

Revisions

View all history