YII2 Modules Modular

Source: Internet
Author: User

The modularity of the YII2 is the ability to make separate modules for easy scaling and porting.

In this way, other YII2 directories need to use the module is copied out, and then configure the next main can be used.

Similar to such a directory, modules is the YII2 of the modular directory, which is written in separate modules.

650) this.width=650; "src=" Http://s4.51cto.com/wyfs02/M02/7B/65/wKiom1bNA3_BWIfIAAAmWmXp-y4441.png "title=" Qq20160224091208.png "alt=" Wkiom1bna3_bwifiaaamwmxp-y4441.png "/>

Each individual module can have a corresponding controllers,models,views,

The submodule must be declared in the parent module's Yii\base\module::modules property, for example:

Namespace Common\modules\rbac;use \yii\base\module;class Rabcmodule extends module{public function init () {    Parent::init (); }}

Configure the module in the main.php configuration file to allow it to be accessed independently

return [' id ' = ' app-backend ', ' basepath ' + dirname (__dir__), ' controllernamespace ' = ' Backend\contro ' Llers ', ' bootstrap ' = [' log '], ' modules ' = [], ' components ' = = [],//module configuration start ' Modules ' =&G T [' rabc ' = [' class ' = ' Common\modules\rbac\rabcmodule ',],],//module configuration end ' params ' = $params,];

As long as there are files in the controllers can be accessed, such as permissioncontroller.php

namespace Common\modules\rbac\controllers;use yii;use Backend\controllers\basecontroller;class Permissioncontroller extends basecontroller{public Function Actionindex () {return $this->render (' index ')    ; }}


Access Link: http://127.0.0.1/index.php?r=rabc/permission/index


YII2 Modules Modular

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.