phpyii2crudgii

Yii2: add field to autogenerated CRUD (automatically?)


Yii2 has a feature of generating CRUD for table with gii.

It creates several files: controller, model, search model and views.

What if after generating CRUD I need to add more fields to the table? I see that I need to change:

A lot of work. Is there a way to do it easier/automatically? I understand that I can just regenerate CRUD with gii, but in this case all my other tweaks would be overwritten (lost).

Maybe there exist some other CRUD solution for Yii2, that does not hardcode all fields and allows table schema changes to appear automatically in the views/models? Would be glad to know about it.


Solution

  • If you dont want to overwrite file or add changes manually , you have below option:

    In Gii, after clicking preview button you can see list of files.

    enter image description here

    If file has changes or already in directory than diff button displayed. On clicking diff button you can see changes in file.

    enter image description here

    From this model (window) you can modify file as your need or you can copy/paste code in/from temporary file and manage.