Home > PHP Framework > YII > What is a module in Yii

What is a module in Yii

(*-*)浩
Release: 2019-12-04 11:22:12
Original
1783 people have browsed it

What is a module in Yii

Modules are independent software units consisting of models, views, controllers and other supporting components. End users can access the controllers of installed modules in the application body. , the module is treated as a small application main body. Different from the application main body, the module cannot be deployed independently and must belong to an application main body.

(Recommended learning: yii frames )

Module is organized as a directory called Base PATH, where There are subdirectories in the directory such as controllers, models, and views, which correspond to controllers, models, views, and other codes respectively, which are very similar to applications. The following example shows the directory structure of a model:

forum/
    Module.php                   模块类文件
    controllers/                 包含控制器类文件
        DefaultController.php    default 控制器类文件
    models/                      包含模型类文件
    views/                       包含控制器视图文件和布局文件
        layouts/                 包含布局文件
        default/                 包含 DefaultController 控制器视图文件
            index.php            index 视图文件
Copy after login

Module class

Each module has a module class that inherits yii\base\Module. This class file directly It is placed in the base path directory of the module and can be loaded automatically. When a module is accessed, a unique instance of the module class is created similar to the application body instance. The module instance is used to help the code within the module share data and components.

The following example is roughly defined as a module class:

namespace app\modules\forum;

class Module extends \yii\base\Module
{
    public function init()
    {
        parent::init();

        $this->params['foo'] = 'bar';
        // ...  其他初始化代码 ...
    }
}
Copy after login

The above is the detailed content of What is a module in Yii. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
yii
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template