1

我正在尝试使用我自己的一组模板来生成由 Tobias Munk 编写的带有 giiant 的 cruds 和模型,如下所示: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',
        ]
    ]
],

];

但是当我从管理员运行巨型表单时,并没有拿起我的代码。

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

模板

欢迎任何想法...

4

2 回答 2

0

您不能更改“ 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' => [...],

'模型' => [...],

ETC

于 2016-07-05T17:23:20.277 回答
0

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

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

下面的配置应该会在选择框中为你带来自己的模型

就我而言,正如我所说,我只是将 /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 Model 中看到我的模板:

我的模板

它工作得很好。

于 2016-07-24T18:15:18.637 回答