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

谈谈yii2-gii如何自定义模板 - 白狼栈

May 20, 2016 am 11:39 AM

作者:白狼 出处: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', 
            ] 
        ] 
    ], 
];
Copy after login

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

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

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

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
WWE 2K25: How To Unlock Everything In MyRise
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)