when I read the codes of yiicms, I found a problem that puzzles me all the time. The problem is discribed aretroactively s follow.
$app = new yii\web\Application($config);
yiibaseapplication::__construct($config);
Component::__construct($config);
- add the debug statement that var_dump($this) later.
- found as follow.
public "bootstrap" =>
array (size=3)
0=>string "log"
1=>string "debug"
2=>string "gii"
private "_modules" (yiibasemodule)=>
array (size=3)
'backend' =>....
'debug' =>...
'gii'=>...
private "_definitions"(yiidiservicelocator)=>
array (size=7)
...
'log'=>...
...
- wonder when and where the private attributes _modules and _definitions are inserted by values 'debug' 'gii' and 'log'?
首先,你的 $config 数组中一定包含以下元素:
这里说明一下继承关系:
上面方法中
Component::__construct($config)
会调用yii\base\Object::__construct()
方法一、下面只是为了说明
'components' => [ 'log' => [...]]
从哪来,若不关心可以直接看 第二步。$this->preInit($config);
,即yii\base\Application::preInit(&$config)
$this->preInit($config);
, 我们得到的$config
上面只是为了说明
'components' => [ 'log' => [...]]
从哪来二、重点在这里
yii\base\Object::__construct($config = [])
中的Yii::configure($this, $config);
yii\base\Object::__set($name, $value)
当前情景下的
$object
我们可以认为是yii\base\Application
的对象$app
这里会调用
yii\base\Module::setModules($modules)
方法这样便有了问题中的
yii\di\ServiceLocator::setComponents($components)
方法这样便有了问题中的