Yii2-related learning Records, custom gii templates, and reference js, css (IV), and yii2gii_PHP tutorials

Source: Internet
Author: User
Yii2-related learning Records, custom gii templates and references js, css (IV), and yii2gii in vendor. Yii2-related learning Records, custom gii templates, and references js and css (IV) in vendor. in yii2gii, the background Template framework has been set up, but there are still some inconsistencies, for example, there are learning records related to Yii2, custom gii templates, and reference js, css (IV), yii2gii

In the previous article, the background Template framework has been set up, but there are still some inconsistencies, such as two User headers, or we want to add or delete some public items when gii is generated. Therefore, we need to define our own gii template.

Taking the CRUD template as an example, the default gii template is located in the default directory of: vendor/yiisoft/yii2-gii/generators/crud, of course, we can create a directory in parallel with default here, but it is not recommended to create a directory here, because it is the vendor directory. as mentioned in the previous chapter, do not change the content under the vendor Directory, in this way, you do not need to submit the vendor Directory during git release or team sharing, which is convenient.

The correct method is to copy the default folder to the location you want to move it to. here I move it to the backend/views/gii/crud directory, then change the gii configuration under the backend/common/main-local.php:

$config['bootstrap'][] = 'gii';$config['modules']['gii'] = [    'class' => 'yii\gii\Module',    'generators' => [ //here        'crud' => [ // generator name            'class' => 'yii\gii\generators\crud\Generator', // generator class            templates' => [ //setting for out templates                'vishun' => '@backend/views/gii/crud/default', // template name => path to template            ]        ]    ],];    

In this way, accessing the CRUD generator in gii will find one more option: (if you change the backend configuration, you can only access gii through the background url)

Remember to replace the copied content, such as deleting the multiple titles, and re-create the content to see the effect after the change. If you are working with a team, you should also write this into the environment.

In our official demo site, we will find that the template integrates many beautiful functions, such as select2 in Forms/Advanced Elements. the drop-down menu is the arrow style. The css select2.min.css is used in firebug‑based css compilation and discovery. Return to our own site and check it again. we will find that our site does not have such a css. So we need to start introducing it, but before that, we need to first understand how to introduce js or css in yii2. The following uses js as an example. css is the same as this:

Method 1: directly the same as in html: (not recommended, leading to dependency disorder)

// External js file

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.