Home > Backend Development > PHP Tutorial > Talk about how to customize templates in yii2-gii

Talk about how to customize templates in yii2-gii

WBOY
Release: 2016-07-29 08:51:53
Original
1264 people have browsed it

Author: Bailang Source: http://www.manks.top/article/yii2_gii_custom_template The copyright of this article belongs to the author, and you are welcome to reprint it. However, this statement must be retained without the author’s consent, and a link to the original text must be provided in an obvious position on the article page. Otherwise, we reserve the right to pursue legal liability.

The gii in yii2 provides us with great convenience in actual use.

However, in actual development, I believe that the templates generated by gii have also brought stability to many developers. Why? Because they are all actively generated using other people's templates, they naturally do not meet the needs of tens of thousands of families. It is better to customize them for your own needs. After all, the official only tries to give a template case as much as possible.

For the introduction of gii and how to use it, please refer to the official documentation. If there is anything you don’t understand, leave a message below and we can communicate together.

yii2 officially only provides one template, but it also provides us with the opportunity to customize it. Next, let’s see how to seize this opportunity to do something.

The template file used by the gii generator is located in the directory vendoriisoftyii2-giigeneratorscruddefault. Because we need to customize the template, we now copy the default directory and paste it into any directory. Here we paste it under giitemplatecurd in the root directory, and then follow the following steps Configure

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

Then we open gii-curd. In the last code template in the curd generator, we can see the customized template. Then, we can modify our own gii template file as we like. .

The above has introduced how to customize templates in yii2-gii, including custom templates and yii content. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template