Yii is a MVC Framework of PHP.
Yii framework offers default crud generation feature. If you write your application name/gii, it will show default crud generation operations. Many times we use different template in project than default crud and need to made changes after watch time crud is generated. This is post to customize default crud to get rid of redundant task.
When you are writing in your application-name/gii ,you are seeing all generators on index.
This generator code is located at yii/framework/gii/views/index.php
Here ,each generator link related code located at yii/framework/gii/generators,
We will extend basic crud and do change in it, so we are able to generate default crud in other applications.
To add your crud generator follow below simple steps:
1. Make folder with your custom name,suppose mycrud under yii/framework/gii/generators.
Make Code file,like myCrudCode in mycrud,which extends CrudCode.
2.Make generator in giiextended folder,like MyCrudGenerator, which extends CrudGenerator.
You need to change in $codeModel ,which give path to code file,
Import : Yii::import(‘gii.generators.crud.CrudGenerator’);
Also make it in mycrud,where $codemodel=ext.giiextended.myCrud.myCrudCode
please notice that,if folder name is mycrud,generate will be name of MycrudGenerator,first letter will be capital.
3.Make Folder template in mycrud folder,in which all views and controller in default folder.Here what you will make changes accordingly future views are generated from your crud.Following views need to be generated as per Yii crud, you can skip 1 or 2 views and change it as per your need, but you need to reflect changes in controller accordingly.
4.Make a folder view,put a index.php in it,
copy it form crud(framework/gii/generators/crud/view/index.php) ,change name in h1 tag.
5.In config/main.php,in gii in generatorpath array,add ext.giiextended.
This will responsible for showing uour customized crud name when you type application-name/gii in url. So try it and you will come out of hustle of each time crud change as new table is generated.
Similaraly,you are able to extend model and form generator also of gii.
Start doing it.All the Best!!!
Have a good day!!!