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 视图文件
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'; // ... 其他初始化代码 ... } }
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!