Module processing operation example of Yii framework

Time:2020-1-12

In this paper, the modular processing operation of the Yii framework is described. To share with you for your reference, as follows:

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;

After adding the sub module, add the management portal configuration in the parent module to realize the function of managing the sub module of the parent module. If the parent module has a bug, the sub module cannot continue to be used

<?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();
    //After adding submodules
    $this->modules = [
      'category' => [
        'class' => 'frontend\modules\article\modules\category\Category',
      ],
    ];
    // custom initialization code goes here
  }
}

For more information about the content of Yii, please refer to the following topics: introduction to Yii framework and summary of common skills, summary of PHP excellent development framework, basic course of smart template introduction, introduction to PHP object-oriented programming, summary of PHP string usage, introduction to PHP + MySQL database operation and PHP common database operation Skills summary

I hope that this article will be helpful for you to Design PHP program based on Yii framework.