YII框架模块化处理操作示例
人气:0本文实例讲述了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框架的PHP程序设计有所帮助。
您可能感兴趣的文章:
加载全部内容