I am learning Yii and I wonder if I generate model and CRUD files using Gii and then I modified these files manually then I changed my database should I run Gii again ? is it going to overwrite my changes in the model files ? if so what is the best solution to update my model , controller and view files to reflect changes in the database without loosing my previous changes ?
Gii is designed to provide you basic code at the beginning, then you modify it to fit your needs.
Yes, if you run it again it will override your files (but you need to explicitly check "Override" checkbox).
So the recommended practice is design database structure as fully as possible first and then generate model / CRUD / with Gii.
Then subsequent changes is done manually without Gii.
A little tip: if you run Gii again, you can view changes in diff and manually copy them.
Once you get more experience, most likely you realize that there is no need to do it.
The real solution to your question is to generate all your initial models by Gii, and keep them untouched in a separate directory e.g app\models\base
and name those models as ModelNameBase
Create your own models at app\models e.g ModelName Let the app\models extend the base models.
This way you may modify app\models as much as you want.
Whenever you have a database change, re-generate the base model.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With