yii2gii

Yii2 custom gii generator and template?


I just implementing a new gii generator for my requirement on yii2. i want to know best place to keep those codes?


Solution

  • Create app\modules\gii directory with own Generator class, views, templates.

    namespace app\modules\gii;
    
    class MyCustomGenerator extends \yii\gii\generators\crud\Generator
    {
        // ...
    
        public function generate()
        {
            // ...
        }
    }
    

    Then enable it in gii configuration.

    [
        // ...
        'modules' => [
            'gii' => [
                'class'      => 'yii\gii\Module',
                'generators' => [
                    'class' => '\app\modules\gii\MyCustomGenerator',
                    'model' => ['class' => '\app\modules\gii\model\MyCustomGenerator'],
                ],
            ],
        ],
    ]