Commit 611052c4 by Qiang Xue

Support preloading modules

parent c0746f06
......@@ -50,7 +50,7 @@ abstract class Module extends Component
*/
public $params = array();
/**
* @var array the IDs of the components that should be preloaded when this module is created.
* @var array the IDs of the components or modules that should be preloaded when this module is created.
*/
public $preload = array();
/**
......@@ -556,11 +556,18 @@ abstract class Module extends Component
/**
* Loads components that are declared in [[preload]].
* @throws InvalidConfigException if a component or module to be preloaded is unknown
*/
public function preloadComponents()
{
foreach ($this->preload as $id) {
if ($this->hasComponent($id)) {
$this->getComponent($id);
} elseif ($this->hasModule($id)) {
$this->getModule($id);
} else {
throw new InvalidConfigException("Unknown component or module: $id");
}
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment