Home  >  Article  >  PHP Framework  >  what is yii gii

what is yii gii

(*-*)浩
(*-*)浩Original
2019-11-04 13:54:192995browse

yii2 is a rapid development framework, in which the gii extension has to be said to be a great help. Code is automatically generated through gii, and some common codes are handed over to the program to generate, which greatly reduces development. the time cost of the person.

what is yii gii

But gii also has some disadvantages, that is, the generated code is the template that comes with yii2, and the code generated every time is not what we want. , so you have to make corresponding adjustments every time.

So how can we make the program generate the code we want? (Recommended learning: yii tutorial)

Yes, the gii extension of yii2 supports custom templates. Through custom templates, we can let gii generate what we want. code, once again saving the time and cost of modifying the generated template.

Configuration

The template file used by the gii generator is located in the directory vendor\yiisoft\yii2-gii\generators\crud\default. Since we want to customize the template, It is best to make adjustments based on the original template.

1. Copy a template, copy the default directory, and place it anywhere. Here we place it in the root directory /backend/giitpl/crud.

2. Modify the template (this article is a tutorial without going into details, you can modify it yourself)

3. Open the configuration file /backend/config/main-local.php and modify $config Configuration of ['modules']['gii'] (as follows):

$config['modules']['gii'] = 
[
    'class' => 'yii\gii\Module',
    'allowedIPs' => ['127.0.0.1', '::1'],
    'generators' => [
        'crud' => [ //生成器名称
            'class' => 'yii\gii\generators\crud\Generator',
            'templates' => [ //设置我们自己的模板
                //模板名 => 模板路径
                'myCrud' => '@backend/giitpl/crud/default',
            ]
        ]
    ],
];

4. Generate code through gii, open the gii interface, and use crud generator to generate code (note: the code template template needs to be modified in the configuration here) )

what is yii gii

Select our customized template and click Generate, then the gii customized template code will be generated.

The above is the detailed content of what is yii gii. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:where are yii componentsNext article:where are yii components