Gii Custom Templates

I’d like to do my own custom templates for Gii, but try as I might, I can’t seem to get Gii to find them, i.e., display them in the Code Template dropdown. Basically, I’ve tried adding this to backend\main\config:


'modules' => [

        'gii' => [

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

            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],

            'generators' => [ //here

                'crud' => [ // generator name

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

                    'templates' => [ //setting for out templates

                        'lel' => 'L:xampp\htdocs\lel\\templates\crud\views', // template name => path to template

                    ]

                ]

            ],

        ],

    ],

‘lel’ is the actual physical address of my custom gii templates. I’ve also tried changing the location to


'lel' => '@app\\templates\crud\views'

, and accessing gii through the backend URL, but that doesn’t work. I don’t get any errors. The templates just don’t show up in the dropdown. Does anyone have any ideas?

For the advanced, you should use ‘@common’, ‘@backend’ or ‘@frontend:)

Actually, @app should get you there when using the backend url to get to gii and all the aliases ultimately map to physical addresses so that should have worked, but nonetheless, I copied the templates folder to my backend folder, inserted the following into backend/config/main.php,


'gii' => [

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

            'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'],

            'generators' => [ //here

                'crud' => [ // generator name

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

                    'templates' => [ //setting for out templates

                        'lel' => '@backend\templates\crud', // template name => path to template

                    ]

                ]

            ],

        ],

and, it still doesn’t work.

Should be forward slashes in the path.

That’s the only thing that I can see that looks wrong.

Again, the slashes shouldn’t matter, but I tried forward slashes. That didn’t help either. It looks like you can’t add custom templates the way “The Book” says you can. It just doesn’t work.

I am doing it.

And by the book, too. :)

Are you sure that it does not get loaded?

Perhaps you need to change the name of the generator in the generator class.

I had one of mine end up replacing one of the built-in generators because I forgot to change the name.

EDIT:

functions getName and getDescription

Now, you’ve totally lost me. If you follow Yii’s own instructions (https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/topics-creating-your-own-templates.md), you just copy the templates to a newly named folder and modify the templates. You never touch the generator class/file. You don’t copy it, you don’t moved it, you don’t touch it. It isn’t involved in creating new templates. You leave it set at ‘class’ => ‘yii\gii\generators\crud\Generator’, // generator class. Are you saying the instructions at https://github.com/yiisoft/yii2-gii/blob/master/docs/guide/topics-creating-your-own-templates.md are incorrect?

Alright…

I get it. :)

Choose the Crud generator - then your new template will be available in the code template dropdown list at the bottom end of the form :)

I guess you already did install it.

If you want a menu item for it, then you need to do what I said you should do, and copy the generator along with the template.

simply add this and select template from drop-down while generating CRUD
yii2_advanced\backend\config\main.php

'modules' => [
    'gii' => [
        'class' => 'yii\gii\Module',
        'generators' => [ // HERE
            'crud' => [
                'class' => 'yii\gii\generators\crud\Generator',
                'templates' => [
                    'adminlte' => '@vendor/dmstr/yii2-adminlte-asset/gii/templates/crud/simple',
                ]
            ]
        ],
    ],
],