Click here for EduSec Demo EduSec Screenshots

How to create custom crud generator templates in Yii2-gii?

On 2014-12-17 - By Hiren Bhut

If you want to apply your new template for default gii crud generator, want to make your own gii crud.

Follow the steps given below:

Create a folder 'EduSec' in your 'yii2application/vendor/yiisoft/yii2-gii/generators/crud/'

1. Create a folder within that called 'EduSec'

2. Into that folder copy the entire contents of `yii2application/vendor/yiisoft/yii2-gii/generators/crud/default'.

3. Then define the templates in your config.

4. Open 'yii2application/config/web.php' change following content in YII_ENV_DEV. Which give path to EduSec folder in your templates.

if (YII_ENV_DEV) {

$config['modules']['gii'] = [

'class'=>'yii\gii\Module',

'generators' => [

'crud' => [

'class' => 'yii\gii\generators\crud\Generator',

'templates' => ['EduSec' => '@app/vendor/yiisoft/yii2-gii/generators/crud/EduSec']

]

],

'allowedIPs'=>['127.0.0.1','192.168.1.*'],

];

}

5. Find all file into 'yii2application/vendor/yiisoft/yii2-gii/generators/crud/EduSec/views' in change your required file.

For Example,

Now we are add new tag '<div class="EduSec-main">' in '_form.php' put this div in your required position in yii2application/vendor/yiisoft/yii2-gii/generators/crud/EduSec/views/_form.php

6. Now open crud generator form in your browser enter the URL like 'http://localhost/yii2application/web/gii/crud' and then select "EduSec (/var/www/EduSec4/vendor/yiisoft/yii2-gii/generators/crud/EduSec)" from Code Template drop down option in crud generator form.

This method has the benefit that you modified the custom crud generator template files.