my model/db design is constantly changing. add column here, delete column there, index here, foreign keys there, you get the idea.
now I use giic to generate the basic CRUD functionality and then add to them. the problem is when i decide to update my model after I modified my CRUD pages. since the model is changed the CRUD pages should also be modified to work properly.
is there a practical way to do this? re-generating the CRUD pages would overwrite my prior modifications. or maybe a clever workaround such as writing my code in a separate class perhaps?
You realy should start from a stable database model. Always analyse your project (at least until you have a database that is more or less stable), before you start coding.
Nevertheless the database will change in time, so you need a solution. For little changes in your model (eg adding an attribute) you could use the preview button and copy the changes to your code (without regenerating the file).
A better solution is using a versioning system. This allows you to return to a previous state of your application. For example, you could use github to keep track of your changes in combination with a client like smartgit. It takes some time to get used to this process, but it’s time well spent.
I modified the gii generator to create two files (and two classes) for each table. The second class is a specialization of the first class. For a "user" table that would mean the following classes
"BaseUser" contains the regular stuff gii creates
"User" simply extends BaseUser and has no implementation yet.
Within your application you just use "User". Any changes you want to make you implement in the User class. If you change your DB design you can simply overwrite the BaseUser class without worrying about the changes you made.
using yii does make me spend more time on the DB design however future modification is inevitable.
what i’m doing currently is similar to dave’s.
although not to the extent of modifying gii (not to keen on using gii more than necessary ). I just replace the controllers base class with my own implementation. this way I get separation between what Gii’s and my own code.