How to Design the yii2 module backend elegantly

Source: Internet
Author: User
Yii2 separates the front and back ends. backend and frontend are configured and used properly. However, third-party modules or self-developed modules are based on frontend, in addition, there is no response setting in the module to distinguish between the foreground and the background. At this time, if the module is registered to the frontend, the internal... yii2 separates the front and back ends. backend and frontend are configured and used properly. However, third-party modules or self-developed modules are based on frontend, in addition, there is no response setting in the module to distinguish between the front-end and the back-end. If the module is registered in frontend, the corresponding internal management controller can actually be accessed in frontend. I mean whether RBAC is used to control the elegant separation, but the front-end cannot access it at all.

Reply content:

Yii2 separates the front and back ends. backend and frontend are configured and used properly. However, third-party modules or self-developed modules are based on frontend, in addition, there is no response setting in the module to distinguish between the front-end and the back-end. If the module is registered in frontend, the corresponding internal management controller can actually be accessed in frontend. I mean whether RBAC is used to control the elegant separation, but the front-end cannot access it at all.

You can create a new module directory in the same directory as frontend and backend, store the public module, and then boot the module as needed. For example, to use the myModule module in frontend, add the following in config:

[    'bootstrap' => [        'myModule',    ],    'modules' => [        'myModule' => 'app\module\myModule',    ],]

Then in the frontend project, you can use$module = myModule::getInstance();Access.

Reference http://www.yiichina.com/doc/guide/2.0/st...

The default advanced template of yii2 already distinguishes the foreground, background, and public directory.
Frontend
Backend
Common

Frontend and backend can depend on common at the same time.
However, frontend and backend do not depend on each other, and all dependencies are stored in the common

The module you created must also be separated by function
Front-end module with frontend
Backend
Common

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.