An in-depth analysis of yii2-gii custom templates _php Examples

Source: Internet
Author: User
Tags generator php framework yii

Objective:

What is YII?

Yii is a high-performance, component-based PHP Framework for rapid development of modern WEB applications. The name Yii (read as ' Easy ') has the dual meaning of "extreme simplicity and continuous evolution" in Chinese, and can also be regarded as **yes It is**! 's initials.

What is the best thing for Yii?

Yii is a common web programming framework that can be used to develop a variety of PHP based Web applications. Because of its component-based framework architecture and well-designed caching support, YII is particularly well suited to developing large applications such as portals, forums, 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 the old version of the legacy and is now in the maintenance state. Version 2.0 is a fully rewritten version with the latest technologies and protocols, including the Dependency Pack Manager (Composer), the PHP Code specification (PSR), namespaces, Traits, and so on. The 2.0 edition represents the latest generation framework and is our major development version in the coming years. This guide is written primarily on version 2.0.

Body:

The YII2 offers great convenience in our actual use.

However, in real-world development, we believe that the templates generated by GII also bring the same to many developers, why? Because they are all using their own template initiative to generate, nature does not meet the needs of thousands, their own needs or customized good, after all, the official is just as far as possible to give a template case.

About the introduction to GII and how to use it can refer to the official documentation, if there is no understanding, the bottom of the message we communicate together.

YII2 official only provides a template, but also gives us a chance to customize, then we see how to seize the opportunity to do something.

The template files used in the GII generator are located in the directory Vendor\yiisoft\yii2-gii\generators\crud\default because to customize the template, we now copy the default directory and paste it into any directory. Here we paste the giitemplate\curd underneath the root directory, and then configure it as follows

$config [' Modules '] [' gii '] = [
' class ' => ' Yii\gii\module ', ' 
allowedips ' => [' 127.0.0.1 ', ':: 1 '], 
' Generators ' => [ 
' 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 we can see the custom templates in the last code template in curd generator, and then we can modify our own gii template files as we wish.

The above is a small set to introduce the Yii2-gii custom template method, I hope to help you!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.