From 710e70b8fdec5d298b5297c665dee554730210a0 Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 2 Oct 2014 13:31:31 -0400 Subject: [PATCH] Fixes #2037: Dropped the support for using `yii\base\Module` as concrete module classes --- docs/guide/structure-modules.md | 8 ++++++-- framework/CHANGELOG.md | 1 + framework/base/Module.php | 3 --- 3 files changed, 7 insertions(+), 5 deletions(-) diff --git a/docs/guide/structure-modules.md b/docs/guide/structure-modules.md index e790ed98cd..af37c2bfe0 100644 --- a/docs/guide/structure-modules.md +++ b/docs/guide/structure-modules.md @@ -29,7 +29,7 @@ forum/ ### Module Classes -Each module should have a module class which extends from [[yii\base\Module]]. The class should be located +Each module should have a unique module class which extends from [[yii\base\Module]]. The class should be located directly under the module's [[yii\base\Module::basePath|base path]] and should be [autoloadable](concept-autoloading.md). When a module is being accessed, a single instance of the corresponding module class will be created. Like [application instances](structure-applications.md), module instances are used to share data and components @@ -173,7 +173,7 @@ different from the one created by Yii in response to a request. You may also access the instance of a module using the following approaches: ```php -// get the module whose ID is "forum" +// get the child module whose ID is "forum" $module = \Yii::$app->getModule('forum'); // get the module to which the currently requested controller belongs @@ -239,6 +239,10 @@ For a controller within a nested module, its route should include the IDs of all For example, the route `forum/admin/dashboard/index` represents the `index` action of the `dashboard` controller in the `admin` module which is a child module of the `forum` module. +> Info: The [[yii\base\Module::getModule()|getModule()]] method only returns the child module directly belonging +to its parent. The [[yii\base\Application::loadedModules]] property keeps a list of loaded modules, including both +direct children and nested ones, indexed by their class names. + ## Best Practices diff --git a/framework/CHANGELOG.md b/framework/CHANGELOG.md index 1c588a43b0..2530ddf7a9 100644 --- a/framework/CHANGELOG.md +++ b/framework/CHANGELOG.md @@ -9,6 +9,7 @@ Yii Framework 2 Change Log - Bug: Date and time formatting now assumes UTC as the timezone for input dates unless a timezone is explicitly given (cebe) - Enh #4275: Added `removeChildren()` to `yii\rbac\ManagerInterface` and implementations (samdark) - Enh: Added `yii\base\Application::loadedModules` (qiangxue) +- Chg #2037: Dropped the support for using `yii\base\Module` as concrete module classes (qiangxue) 2.0.0-rc September 27, 2014 diff --git a/framework/base/Module.php b/framework/base/Module.php index d301421517..4fa92972ed 100644 --- a/framework/base/Module.php +++ b/framework/base/Module.php @@ -350,9 +350,6 @@ class Module extends ServiceLocator return $this->_modules[$id]; } elseif ($load) { Yii::trace("Loading module: $id", __METHOD__); - if (is_array($this->_modules[$id]) && !isset($this->_modules[$id]['class'])) { - $this->_modules[$id]['class'] = 'yii\base\Module'; - } /* @var $module Module */ $module = Yii::createObject($this->_modules[$id], [$id, $this]); $module->setInstance($module);