Yii v2 snippet guide

Comparing #47 with #48

Revision #48 was created by rackycz rackycz on Sep 20, 2019, 12:47:31 PM.

edit

Content

[...]
If you must use MyISAM instead of InnoDB, just change the word InnoDB into MYISAM.

Then use GII to generate model + CRUD. 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"
 
 
- 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 te 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

The final model should look like this:
[...]