search
Homephp教程php手册谈谈yii2-gii如何自定义模板 - 白狼栈

作者:白狼 出处:http://www.manks.top/article/yii2_gii_custom_template本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。

yii2中gii给我们实际的使用提供了很大的方便。

但是,实际开发中,相信gii生成的模板也给很多开发者带来了不变,为啥?因为都是都是用人家的模板主动性生成的,自然不满足千万家的需求了,自家的需求还是自家定制的好,毕竟官方也只是尽可能的给出一个模板案例。

关于gii的介绍以及怎么使用可参考官方文档说明,如果有哪里不懂的,下方留言我们共同交流。

yii2官方只提供了一种模板,但是也给我们提供了自定义的机会,接下来我们看看如何抓住这个机会去做点什么。

gii生成器所用到的模板文件位于目录 vendor\yiisoft\yii2-gii\generators\crud\default,因为要自定义模板,我们现在把default目录拷贝一份,粘贴到任意目录,这里我们粘贴在根目录下的giitemplate\curd下面,然后按照下面进行配置

$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', 
            ] 
        ] 
    ], 
];

然后我们打开gii-curd,在curd generator内最后一项code template中,我们就可以看到自定义的模板了,那么接下来,我们就可以随心所欲的修改我们自己的gii模板文件了。

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.