Yii is a high-performance, Component-Based PHP framework for rapid development of modern Web applications. Next through this article to introduce you to the yii2-gii custom template method, need a friend to refer to it
Preface:
What is Yii?
Yii is a high-performance, Component-Based PHP framework for rapid development of modern Web applications. The name Yii has two meanings: "Ultimate simplicity and constant evolution" in Chinese. It can also be seen as ** Yes It Is **! .
What is Yii most suitable?
Yii is a general Web programming framework that can be used to develop various PHP-based Web applications. Because of the component-based framework structure and well-designed cache support, Yii is particularly suitable for developing large applications, such as portal websites, forums, and content management systems (CMS) e-commerce projects and RESTful Web Services.
Yii version
Yii currently has two major versions: 1.1 and 2.0. Version 1.1 is an old version of the previous generation and is currently under maintenance. Version 2.0 is a fully rewritten version that uses the latest technologies and protocols, including dependency Package Manager (Composer), PHP code specification (PSR), namespace, Traits (Traits) and so on. Version 2.0 represents the latest framework and is our main development version in the next few years. This guide is mainly based on the 2.0 version.
Body:
Gii in yii2 provides great convenience for our actual use.
However, in actual development, I believe that the template generated by gii will not change for many developers. Why? Because they are all generated proactively using templates from other people's homes, they naturally do not meet the needs of thousands of homes, and their own needs are well customized. After all, the official website only provides a template case as much as possible.
For details about gii and how to use it, refer to the official documentation. If you do not know anything about gii, please share your comments below.
Yii2 only provides one template, but also provides us with a custom opportunity. Next, let's take a look at how to seize this opportunity to do something.
The template file used by the gii generator is located in the vendor \ yiisoft \ yii2-gii \ generators \ crud \ default directory. to customize the template, copy the default directory, paste it to any directory. Here we paste it under the giitemplate \ curd under the root directory, and then configure it as follows:
$ Config ['modules'] ['giii '] = ['class' => 'yii \ gii \ module', 'allowedips' => ['123. 0.0.1 ',': 1'], 'generator' => ['crud '=> [// Generator name 'class' => 'yii \ gii \ generators \ crud \ generator ', 'templates' => [// set our own template // Template Name => template path 'mycrud '=>' @ app/giitemplate/crud/default',] ,];
Then we open gii-curd, and in the last code template in curd generator, we can see the Custom template. Then, we can modify our gii template file as needed.
The above is a small Editor to introduce you to the yii2-gii custom template method, hope to help everyone!