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

2020-10-21 10:40:04 浏览数 (1)

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

config.php

代码语言:javascript复制
$config = [
  'modules' =  [
    'comment' =  [
      'class' =  'frontendmodulescommentComment',
    ],
    'article' =  [
      'class' =  'frontendmodulesarticleArticle',
      'modules' =  [
        'category' =  [
          'class' =  'frontendmodulesarticlemodulescategoryCategory',
        ],
        'title' =  [
            'class' =  'frontendmodulesarticlemodulestitleTitle',
        ],
      ],
    ],
  ],
];
if (!YII_ENV_TEST) {
  // configuration adjustments for 'dev' environment
  $config['bootstrap'][] = 'debug';
  $config['modules']['debug'] = [
    'class' =  'yiidebugModule',
  ];
  $config['bootstrap'][] = 'gii';
  $config['modules']['gii'] = [
    'class' =  'yiigiiModule',
  ];
}
return $config;

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

代码语言:javascript复制
<?php
namespace frontendmodulesarticle;
/**
 * article module definition class
 */
class Article extends yiibaseModule
{
  /**
   * @inheritdoc
   */
  public $controllerNamespace = 'frontendmodulesarticlecontrollers';
  /**
   * @inheritdoc
   */
  public function init()
  {
    parent::init();
    //添加子模块后
    $this- modules = [
      'category' =  [
        'class' =  'frontendmodulesarticlemodulescategoryCategory',
      ],
    ];
    // custom initialization code goes here
  }
}

0 人点赞