An in-depth analysis of the method of customizing templates in yii2-gii

WBOY
Release: 2016-07-29 08:51:55
Original
1051 people have browsed it

Foreword:

What is Yii

Yii is a high-performance, component-based PHP framework for rapid development of modern web applications. The name Yii (pronounced `易`) has two meanings in Chinese: "Extreme simplicity and continuous evolution", and can also be regarded as the abbreviation of **Yes It Is**!

What is Yii best suited for?

Yii is a general web programming framework that can be used to develop various PHP-based web applications. Because of its component-based framework structure and well-designed caching support, Yii is particularly suitable for developing large-scale applications, such as portals, forums, content management systems (CMS), e-commerce projects, and RESTful web services.

Yii Versions

Yii currently has two major versions: 1.1 and 2.0. Version 1.1 is an older version of the previous generation and is currently under maintenance. Version 2.0 is a completely rewritten version, using the latest technologies and protocols, including dependency package manager (Composer), PHP Code Specification (PSR), namespaces, Traits (traits), etc. Version 2.0 represents the latest generation of the framework and will be our main development release over the next few years. This guide is primarily based on version 2.0.

Text:

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 as we like. template file.

The above is the method of yii2-gii custom template introduced by the editor. I hope it will be helpful to everyone!

The above introduces the method of in-depth analysis of yii2-gii custom templates, 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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!