Yii has some great features for simplifying and automating portions of development. Two key areas are...
- Gii generating model classes based on table schemas
- Using the
yiic migrate
command to manage schema changes
I am proposing two enhancements to these areas. For Gii model generation, I suggest that it create separate Base and extending classes (https://gist.github.com/fillup/5cdba5990c6576bbbfb0). In this Gist I propose that the migration support is enhanced to add a parameter for automatically regenerating the base classes for affected (or all) tables.
My ideal workflow would be:
./yiic migrate create create_table_user
// migration for creating a table named 'user'- Edit the migration file to define the schema for the 'user' table
- Execute the migration:
./yiic migrate --gii-create-classes
- With the flag
--gii-create-classes
provided, migrate would work with Gii to generate two class files: UserBase and User. UserBase would match the file that Gii currently generates and User would be an empty class that extends UserBase. ./yiic migrate create alter_user_table
// create migration to modify the table named 'user'- Edit the migration file to alter the table
- Execute the migration:
./yiic migrate --gii-create-classes
- With the flag
--gii-create-classes
provided, gii sees that the extending class already exists so it only recreates the Base class
With this flow I'm able to focus on my database schemas/migrations and Yii/Gii takes care of model class file (re)generation.