php教程

超轻量级php框架startmvc

YII框架模块化处理操作示例

更新时间:2020-04-04 18:53:35 作者:startmvc
本文实例讲述了YII框架模块化处理操作。分享给大家供大家参考,具体如下:config.php$config=

本文实例讲述了YII框架模块化处理操作。分享给大家供大家参考,具体如下:

config.php


$config = [
 'modules' => [
 'comment' => [
 'class' => 'frontend\modules\comment\Comment',
 ],
 'article' => [
 'class' => 'frontend\modules\article\Article',
 'modules' => [
 'category' => [
 'class' => 'frontend\modules\article\modules\category\Category',
 ],
 'title' => [
 'class' => 'frontend\modules\article\modules\title\Title',
 ],
 ],
 ],
 ],
];
if (!YII_ENV_TEST) {
 // configuration adjustments for 'dev' environment
 $config['bootstrap'][] = 'debug';
 $config['modules']['debug'] = [
 'class' => 'yii\debug\Module',
 ];
 $config['bootstrap'][] = 'gii';
 $config['modules']['gii'] = [
 'class' => 'yii\gii\Module',
 ];
}
return $config;

添加子模块后,在父模块添加管理入口配置,实现父模块管理子模块功能,如果父模块出现bug,子模块将无法继续使用


<?php
namespace frontend\modules\article;
/**
 * article module definition class
 */
class Article extends \yii\base\Module
{
 /**
 * @inheritdoc
 */
 public $controllerNamespace = 'frontend\modules\article\controllers';
 /**
 * @inheritdoc
 */
 public function init()
 {
 parent::init();
 //添加子模块后
 $this->modules = [
 'category' => [
 'class' => 'frontend\modules\article\modules\category\Category',
 ],
 ];
 // custom initialization code goes here
 }
}

YII框架 模块化