1.1 layout查找顺序

在应用中添加了一个模块,但是还没有给模块添加layouts,结果发现页面还是可以正常显示,只是layout用的是应用级的layout,有点好奇,于是跟了下代码,在yii2\base\Controller.php的findLayoutFile()看到有如下代码:

public function findLayoutFile($view)
{
$module = $this->module;
if (is_string($this->layout)) {
$layout = $this->layout;
} elseif ($this->layout === null) {
while ($module !== null && $module->layout === null) {
$module = $module->module;
}
if ($module !== null && is_string($module->layout)) {
$layout = $module->layout;
}
}

红色部分代码含义就是当在当前模块没有找到layout时,就上溯到父模块,寻找父模块的layout,以此类推,直到最后找到可用的layout。