Skip to content

Instantly share code, notes, and snippets.

@fillup
fillup / gii-create-base-and-extending-classes.md
Last active August 29, 2015 14:02
Proposal for Yii2 Gii Model generation to create base class and extending class

Gii provides a very easy way to generate Model classes from a database schema. However, model classes often need to be modified in order to add functionality. Once the model has been modified, you can no longer use Gii to create new versions of the model class when the database schema changes.

As a better practice one should use Gii to generate a base class, then create an extending class that is modified as needed. This allows Gii to regenerate the Base class as often as needed whenever the table schema changes.

Ideally Gii would provide an option to automatically generate both the Base class file and the Extending class file if it does not already exist. I think it would be great if part of the Gii configuration had an option to provide a "Base Class Suffix" that would be appended to the base class name and file name and then the extending class file would be created and extend it properly.

For example, for a “user” database table, Gii could create a class/file named UserBase. If there is no User class/f