Is there a way we can build Yii model without deleting the my code in Model?
Overwrite and diff are the only options for me to see before and after my Model is overwritten without existence of my additional useful functions (that I implemented)inside the model . This means my code within the model will also be deleted when I rebuild my models.
Please help me anyone who know how to deal with this issue, it will be very thankful and helpful to other Yii user as well.
Thanks!! Yeah I think I will have to do that way finally, though it takes time.
I definitely need to re-build the models to handle the system extension in the future. As I am only working on the beginning of implementation phase of the system, there is not a big deal to handle the change of my models, but some of my models have so many relatives so when I want to change a model, it will effect all relative models as well. As the result, I have to spend more time repairing(Ex: taking the whole related helper function in my old model to my new model…etc) the whole system every time I regenerate the model.
I’ve also wanted to create extensions to various auto-generated models, for example to add helper functions to a model class that represents a database table. I went with the subclass option too, so that I can still regenerate the underlying base class as necessary without affecting the customizations in my subclass.
One thing to note is that I had to make sure to override the model() static function in my subclass to make sure everything worked nicely. For example, consider a User model that is generated by Gii and a MyUser subclass of User. In order for the following to still work (i.e., to return an instance of MyUser, not User):
$user = MyUser::model()->findAll();
You should define your subclass like:
class MyUser extends User
public static function model($className=__CLASS__)
... the rest of your functions ...