使用 yii2 giiant 添加自定义模型模板

Add custom model template using yii2 giiant

我正在尝试使用我自己的模板集来生成 cruds 和模型以及 Tobias Munk 的 giiant 和以下内容:https://github.com/schmunk42/yii2-giiant/blob/master/docs/32-customizations.md

但我做不到。

首先我将 /yii2-giiant/src/generators 目录复制到我的应用程序中并做了一些更改。

然后我将配置更改如下:

$config['modules']['gii'] = [
'class'      => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1'],
'generators' => [
    // generator name
    'giiant-model' => [
        //generator class
        'class'     => 'schmunk42\giiant\generators\model\Generator',
        //setting for out templates
        'templates' => [
            // template name => path to template
            'oemodel' =>
                '@app/oetemplates/model/default',
        ]
    ]
],

];

但是当我 运行 来自管理员的巨大表单没有获取我的代码时。

我还可以在表单中看到一个 select 框,其中显示了带有模板的默认目录。但不确定如何在那里添加我的。

欢迎提出任何想法...

您无法更改“generators”键,即

应该是:

$config['modules']['gii'] = [
'class'      => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1'],
'generators' => [
    // generator name
    'model' => [
        //generator class
        'class'     => 'schmunk42\giiant\generators\model\Generator',
        //setting for out templates
        'templates' => [
            // template name => path to template
            'oemodel' =>
                '@app/oetemplates/model/default',
        ]
    ]
],

// 生成器名称应该是

'crud' => [...],

'model' => [...],

等等

我遵循 schmunk42 文档的方式很好,但不确定为什么它不起作用。可能我没有测试正确或者我没有在正确的地方添加配置。

但是如果您正在使用 schmunk42/yii2-giiant 模块,并且您想使用自己的模板生成代码而不接触该模块。

下面的配置应该会在select框中带上你自己的模型

在我的例子中,正如我所说,我只是将 /yii2-giiant/src/generators 目录复制到我的应用程序(在我的例子中)在 oetemplates 中:

    $config['modules']['gii'] = [
    'class' => 'yii\gii\Module',
    'allowedIPs' => $allowedIPs,
];

$giiant = require __DIR__.'/giiant.php';
$config = \yii\helpers\ArrayHelper::merge($config, $giiant);

$config['modules']['gii'] = [
    'class'      => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1'],
    'generators' => [
        // generator name
        'giiant-model' => [
            //generator class
            'class'     => 'schmunk42\giiant\generators\model\Generator',
            //setting for out templates
            'templates' => [
                // template name => path to template
                'oemodel' =>
                    '@app/oetemplates/model/default',
            ]
        ]
    ],
];

然后当我转到后端时,我可以在 Giiant 模型中看到我的模板:

而且效果很好。