An in-depth analysis of yii2-gii custom template methods _php instances

Source: Internet
Author: User
Tags php framework traits yii
Preface:

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 constant evolution" in Chinese, also can be regarded as **yes It is**! The abbreviation.

What is Yii best suited to do?

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 and well-designed cache support, YII is ideal for developing large-scale applications such as portals, forums, Content management systems (CMS), e-commerce projects, and RESTful WEB services.

Yii version

There are currently two major versions of YII: 1.1 and 2.0. Version 1.1 is the old version, and is now in the maintenance state. Version 2.0 is a fully rewritten version that incorporates the latest technologies and protocols, including the dependency Package Manager (Composer), PHP Code specification (PSR), namespaces, Traits (traits), and more. Version 2.0 represents the latest generation of frameworks and is our main development in the coming years. This guide is primarily based on version 2.0.

Body:

The GII in Yii2 provides a great convenience for our practical use.

However, in actual development, we believe that the template generated by the GII has also brought the same to many developers, why? Because all are the template initiative generated by others, nature does not meet the needs of the thousands, the needs of their own custom is good, after all, the official is just as far as possible to give a template case.

For an introduction to the GII and how to use it, refer to the official documentation, and if there is anything you don't understand, we'll share the message below.

YII2 official only provided a template, but also gave us the opportunity to customize, next we see how to seize the opportunity to do something.

The template file used by the GII generator is located in directory Vendor\yiisoft\yii2-gii\generators\crud\default, because to customize the template, we now copy the default directory, paste it into any directory, Here we paste the Giitemplate\curd under 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, in the last code template in curd generator, we can see the custom template, then we can modify our own gii template file as we like.

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

  • 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.