Open wangming1993 opened 8 years ago
在yii\base\View中的 findViewFile($view, $context = null) 中 存在 5种view的处理方式:
yii\base\View
findViewFile($view, $context = null)
view
if (strncmp($view, '@', 1) === 0) { // e.g. "@app/views/main" $file = Yii::getAlias($view); } elseif (strncmp($view, '//', 2) === 0) { // e.g. "//layouts/main" $file = Yii::$app->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/'); } elseif (strncmp($view, '/', 1) === 0) { // e.g. "/site/index" if (Yii::$app->controller !== null) { $file = Yii::$app->controller->module->getViewPath() . DIRECTORY_SEPARATOR . ltrim($view, '/'); } else { throw new InvalidCallException("Unable to locate view file for view '$view': no active controller."); } } elseif ($context instanceof ViewContextInterface) { $file = $context->getViewPath() . DIRECTORY_SEPARATOR . $view; } elseif (($currentViewFile = $this->getViewFile()) !== false) { $file = dirname($currentViewFile) . DIRECTORY_SEPARATOR . $view; } else { throw new InvalidCallException("Unable to resolve view file for view '$view': no active view context."); }
在yii\base\Controller中的 findLayoutFile($view) 中 存在 3种layout的处理方式:
yii\base\Controller
findLayoutFile($view)
layout
if (strncmp($layout, '@', 1) === 0) { $file = Yii::getAlias($layout); } elseif (strncmp($layout, '/', 1) === 0) { $file = Yii::$app->getLayoutPath() . DIRECTORY_SEPARATOR . substr($layout, 1); } else { $file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $layout; }
Yii2 controller中如何设置layout和view的路径
在
yii\base\View
中的findViewFile($view, $context = null)
中 存在 5种view
的处理方式:在
yii\base\Controller
中的findLayoutFile($view)
中 存在 3种layout
的处理方式: