|
|
|
@ -22,15 +22,15 @@ use yii\di\ServiceLocator;
|
|
|
|
|
* accessible within the module. |
|
|
|
|
* |
|
|
|
|
* @property array $aliases List of path aliases to be defined. The array keys are alias names (must start |
|
|
|
|
* with '@') and the array values are the corresponding paths or aliases. See [[setAliases()]] for an example. |
|
|
|
|
* with `@`) and the array values are the corresponding paths or aliases. See [[setAliases()]] for an example. |
|
|
|
|
* This property is write-only. |
|
|
|
|
* @property string $basePath The root directory of the module. |
|
|
|
|
* @property string $controllerPath The directory that contains the controller classes. This property is |
|
|
|
|
* read-only. |
|
|
|
|
* @property string $layoutPath The root directory of layout files. Defaults to "[[viewPath]]/layouts". |
|
|
|
|
* @property string $layoutPath The root directory of layout files. Defaults to `[[viewPath]]/layouts`. |
|
|
|
|
* @property array $modules The modules (indexed by their IDs). |
|
|
|
|
* @property string $uniqueId The unique ID of the module. This property is read-only. |
|
|
|
|
* @property string $viewPath The root directory of view files. Defaults to "[[basePath]]/views". |
|
|
|
|
* @property string $viewPath The root directory of view files. Defaults to `[[basePath]]/views`. |
|
|
|
|
* |
|
|
|
|
* @author Qiang Xue <qiang.xue@gmail.com> |
|
|
|
|
* @since 2.0 |
|
|
|
@ -56,7 +56,7 @@ class Module extends ServiceLocator
|
|
|
|
|
*/ |
|
|
|
|
public $id; |
|
|
|
|
/** |
|
|
|
|
* @var Module the parent module of this module. Null if this module does not have a parent. |
|
|
|
|
* @var Module the parent module of this module. `null` if this module does not have a parent. |
|
|
|
|
*/ |
|
|
|
|
public $module; |
|
|
|
|
/** |
|
|
|
@ -70,7 +70,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* Each name-value pair specifies the configuration of a single controller. |
|
|
|
|
* A controller configuration can be either a string or an array. |
|
|
|
|
* If the former, the string should be the fully qualified class name of the controller. |
|
|
|
|
* If the latter, the array must contain a 'class' element which specifies |
|
|
|
|
* If the latter, the array must contain a `class` element which specifies |
|
|
|
|
* the controller's fully qualified class name, and the rest of the name-value pairs |
|
|
|
|
* in the array are used to initialize the corresponding controller properties. For example, |
|
|
|
|
* |
|
|
|
@ -91,15 +91,15 @@ class Module extends ServiceLocator
|
|
|
|
|
* class name. |
|
|
|
|
* |
|
|
|
|
* If not set, it will use the `controllers` sub-namespace under the namespace of this module. |
|
|
|
|
* For example, if the namespace of this module is "foo\bar", then the default |
|
|
|
|
* controller namespace would be "foo\bar\controllers". |
|
|
|
|
* For example, if the namespace of this module is `foo\bar`, then the default |
|
|
|
|
* controller namespace would be `foo\bar\controllers`. |
|
|
|
|
* |
|
|
|
|
* See also the [guide section on autoloading](guide:concept-autoloading) to learn more about |
|
|
|
|
* defining namespaces and how classes are loaded. |
|
|
|
|
*/ |
|
|
|
|
public $controllerNamespace; |
|
|
|
|
/** |
|
|
|
|
* @var string the default route of this module. Defaults to 'default'. |
|
|
|
|
* @var string the default route of this module. Defaults to `default`. |
|
|
|
|
* The route may consist of child module ID, controller ID, and/or action ID. |
|
|
|
|
* For example, `help`, `post/create`, `admin/post/create`. |
|
|
|
|
* If action ID is not given, it will take the default value as specified in |
|
|
|
@ -127,9 +127,9 @@ class Module extends ServiceLocator
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Constructor. |
|
|
|
|
* @param string $id the ID of this module |
|
|
|
|
* @param Module $parent the parent module (if any) |
|
|
|
|
* @param array $config name-value pairs that will be used to initialize the object properties |
|
|
|
|
* @param string $id the ID of this module. |
|
|
|
|
* @param Module $parent the parent module (if any). |
|
|
|
|
* @param array $config name-value pairs that will be used to initialize the object properties. |
|
|
|
|
*/ |
|
|
|
|
public function __construct($id, $parent = null, $config = []) |
|
|
|
|
{ |
|
|
|
@ -142,7 +142,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* Returns the currently requested instance of this module class. |
|
|
|
|
* If the module class is not currently requested, `null` will be returned. |
|
|
|
|
* This method is provided so that you access the module instance from anywhere within the module. |
|
|
|
|
* @return static|null the currently requested instance of this module class, or null if the module class is not requested. |
|
|
|
|
* @return static|null the currently requested instance of this module class, or `null` if the module class is not requested. |
|
|
|
|
*/ |
|
|
|
|
public static function getInstance() |
|
|
|
|
{ |
|
|
|
@ -239,7 +239,7 @@ class Module extends ServiceLocator
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the directory that contains the view files for this module. |
|
|
|
|
* @return string the root directory of view files. Defaults to "[[basePath]]/views". |
|
|
|
|
* @return string the root directory of view files. Defaults to `[[basePath]]/views`. |
|
|
|
|
*/ |
|
|
|
|
public function getViewPath() |
|
|
|
|
{ |
|
|
|
@ -252,7 +252,7 @@ class Module extends ServiceLocator
|
|
|
|
|
/** |
|
|
|
|
* Sets the directory that contains the view files. |
|
|
|
|
* @param string $path the root directory of view files. |
|
|
|
|
* @throws InvalidParamException if the directory is invalid |
|
|
|
|
* @throws InvalidParamException if the directory is invalid. |
|
|
|
|
*/ |
|
|
|
|
public function setViewPath($path) |
|
|
|
|
{ |
|
|
|
@ -261,7 +261,7 @@ class Module extends ServiceLocator
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Returns the directory that contains layout view files for this module. |
|
|
|
|
* @return string the root directory of layout files. Defaults to "[[viewPath]]/layouts". |
|
|
|
|
* @return string the root directory of layout files. Defaults to `[[viewPath]]/layouts`. |
|
|
|
|
*/ |
|
|
|
|
public function getLayoutPath() |
|
|
|
|
{ |
|
|
|
@ -287,10 +287,10 @@ class Module extends ServiceLocator
|
|
|
|
|
* This method calls [[Yii::setAlias()]] to register the path aliases. |
|
|
|
|
* This method is provided so that you can define path aliases when configuring a module. |
|
|
|
|
* @property array list of path aliases to be defined. The array keys are alias names |
|
|
|
|
* (must start with '@') and the array values are the corresponding paths or aliases. |
|
|
|
|
* (must start with `@`) and the array values are the corresponding paths or aliases. |
|
|
|
|
* See [[setAliases()]] for an example. |
|
|
|
|
* @param array $aliases list of path aliases to be defined. The array keys are alias names |
|
|
|
|
* (must start with '@') and the array values are the corresponding paths or aliases. |
|
|
|
|
* (must start with `@`) and the array values are the corresponding paths or aliases. |
|
|
|
|
* For example, |
|
|
|
|
* |
|
|
|
|
* ```php |
|
|
|
@ -361,7 +361,7 @@ class Module extends ServiceLocator
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
* Adds a sub-module to this module. |
|
|
|
|
* @param string $id module ID |
|
|
|
|
* @param string $id module ID. |
|
|
|
|
* @param Module|array|null $module the sub-module to be added to this module. This can |
|
|
|
|
* be one of the following: |
|
|
|
|
* |
|
|
|
@ -384,7 +384,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* @param boolean $loadedOnly whether to return the loaded sub-modules only. If this is set `false`, |
|
|
|
|
* then all sub-modules registered in this module will be returned, whether they are loaded or not. |
|
|
|
|
* Loaded modules will be returned as objects, while unloaded modules as configuration arrays. |
|
|
|
|
* @return array the modules (indexed by their IDs) |
|
|
|
|
* @return array the modules (indexed by their IDs). |
|
|
|
|
*/ |
|
|
|
|
public function getModules($loadedOnly = false) |
|
|
|
|
{ |
|
|
|
@ -424,7 +424,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* ] |
|
|
|
|
* ``` |
|
|
|
|
* |
|
|
|
|
* @param array $modules modules (id => module configuration or instances) |
|
|
|
|
* @param array $modules modules (id => module configuration or instances). |
|
|
|
|
*/ |
|
|
|
|
public function setModules($modules) |
|
|
|
|
{ |
|
|
|
@ -441,7 +441,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* @param string $route the route that specifies the action. |
|
|
|
|
* @param array $params the parameters to be passed to the action |
|
|
|
|
* @return mixed the result of the action. |
|
|
|
|
* @throws InvalidRouteException if the requested route cannot be resolved into an action successfully |
|
|
|
|
* @throws InvalidRouteException if the requested route cannot be resolved into an action successfully. |
|
|
|
|
*/ |
|
|
|
|
public function runAction($route, $params = []) |
|
|
|
|
{ |
|
|
|
@ -534,7 +534,7 @@ class Module extends ServiceLocator
|
|
|
|
|
* |
|
|
|
|
* Note that this method does not check [[modules]] or [[controllerMap]]. |
|
|
|
|
* |
|
|
|
|
* @param string $id the controller ID |
|
|
|
|
* @param string $id the controller ID. |
|
|
|
|
* @return Controller the newly created controller instance, or `null` if the controller ID is invalid. |
|
|
|
|
* @throws InvalidConfigException if the controller class and its file name do not match. |
|
|
|
|
* This exception is only thrown when in debug mode. |
|
|
|
|