Customize default yii application structure

To create yii application, command is ./yiic/webapp app-name.
Application is generated under framework folder and it is as per default yii defined structure.
This guide is to customize the structure of default Yii application generation.

The default webapplication created is copy of  yii/framework/cli/views/webapp.
To customize it, one can change it directly, but it is not recommended way.
We should make a copy of it and save as different name like mywebapp.
New copy should be in same folder  yii/framework/cli/views.
Make all changes as per your file structure and change in code, add components,theme for your application in it.

Open webappcommand.php file from   yii/frameworkcli/commands.
We need to change SourceDir name to our new name.Change following line in code

Now our new yii web application structure is ready.
Run ./yiic webapp app-name,& It will make a application as per your changes.
You can generate application yii default or customize by changing source directory in webappcommand.php file.
Start customizing it!!!
All the best!!!
Have a good day!!!


Yii:Customize default gii base crud

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.
Let’s begin.

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,
here myCode.
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.

  •   _form.php
  •   _search.php
  •   _view.php
  •  admin.php
  •  controller.php
  •  create.php
  •  update.php
  •  index.php
  •  view.php

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.
as example:
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!!!