Yii2 - Gii generators - how to custom crud templates


1. Create your template folders in your application
yii2 - custom gii crud templates - folder structure








- The name of my template is "ndt"












2. Copy "default" templates content, then paste into your template folder.
Here is "ndt" folder

3. Configure your application to declare the new template.
- Edit config/main-local.php, paste these configuration below: 

if (!YII_ENV_PROD) {
  // configuration adjustments for 'dev' environment
  $config['bootstrap'][] = 'debug';
  $config['modules']['debug'] = [
   'class' => 'yii\debug\Module',
   'allowedIPs' => ['127.0.0.1', '::1', '192.168.*.*', '10.61.195.143'] // adjust this to your needs
  ];

  $config['bootstrap'][] = 'gii';
  $config['modules']['gii'] = [
   'class' => 'yii\gii\Module',
  'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.146.93'],
  'generators' => [ //here
      'crud' => [ // generator name
   'class' => 'yii\gii\generators\crud\Generator', // generator class
   'templates' => [ //setting for out templates
       'lel' => '@app/gii-generators/crud/ndt', // template name => path to template
   ]
      ]
  ],
  ];
}

return $config;

4. Custom your own templates, then run gii
On crud generator page, choose your new template
5. Enjoy the result.


No comments:

Post a Comment