Browse Source

Support preloading modules

tags/2.0.0-beta
Qiang Xue 12 years ago
parent
commit
611052c4cf
  1. 9
      framework/yii/base/Module.php

9
framework/yii/base/Module.php

@ -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");
}
}
}

Loading…
Cancel
Save