yiiyii2gii

Using Gii afer updating model files


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 ?


Solution

  • 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.