Home > php教程 > php手册 > body text

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

WBOY
Release: 2016-05-20 11:39:18
Original
983 people have browsed it

作者:白狼 出处: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模板文件了。

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!