Commit 1fe7f5aa by Qiang Xue

Fixes #1335: findLayoutFile() should respect View::defaultExtension.

parent af778d1a
...@@ -305,7 +305,7 @@ class Controller extends Component implements ViewContextInterface ...@@ -305,7 +305,7 @@ class Controller extends Component implements ViewContextInterface
public function render($view, $params = []) public function render($view, $params = [])
{ {
$output = $this->getView()->render($view, $params, $this); $output = $this->getView()->render($view, $params, $this);
$layoutFile = $this->findLayoutFile(); $layoutFile = $this->findLayoutFile($this->getView());
if ($layoutFile !== false) { if ($layoutFile !== false) {
return $this->getView()->renderFile($layoutFile, ['content' => $output], $this); return $this->getView()->renderFile($layoutFile, ['content' => $output], $this);
} else { } else {
...@@ -386,38 +386,39 @@ class Controller extends Component implements ViewContextInterface ...@@ -386,38 +386,39 @@ class Controller extends Component implements ViewContextInterface
/** /**
* Finds the applicable layout file. * Finds the applicable layout file.
* @param View $view the view object to render the layout file
* @return string|boolean the layout file path, or false if layout is not needed. * @return string|boolean the layout file path, or false if layout is not needed.
* Please refer to [[render()]] on how to specify this parameter. * Please refer to [[render()]] on how to specify this parameter.
* @throws InvalidParamException if an invalid path alias is used to specify the layout * @throws InvalidParamException if an invalid path alias is used to specify the layout
*/ */
protected function findLayoutFile() protected function findLayoutFile($view)
{ {
$module = $this->module; $module = $this->module;
if (is_string($this->layout)) { if (is_string($this->layout)) {
$view = $this->layout; $layout = $this->layout;
} elseif ($this->layout === null) { } elseif ($this->layout === null) {
while ($module !== null && $module->layout === null) { while ($module !== null && $module->layout === null) {
$module = $module->module; $module = $module->module;
} }
if ($module !== null && is_string($module->layout)) { if ($module !== null && is_string($module->layout)) {
$view = $module->layout; $layout = $module->layout;
} }
} }
if (!isset($view)) { if (!isset($layout)) {
return false; return false;
} }
if (strncmp($view, '@', 1) === 0) { if (strncmp($layout, '@', 1) === 0) {
$file = Yii::getAlias($view); $file = Yii::getAlias($layout);
} elseif (strncmp($view, '/', 1) === 0) { } elseif (strncmp($layout, '/', 1) === 0) {
$file = Yii::$app->getLayoutPath() . DIRECTORY_SEPARATOR . $view; $file = Yii::$app->getLayoutPath() . DIRECTORY_SEPARATOR . $layout;
} else { } else {
$file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $view; $file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $layout;
} }
if (pathinfo($file, PATHINFO_EXTENSION) === '') { if (pathinfo($file, PATHINFO_EXTENSION) === '') {
$file .= '.php'; $file .= $view->defaultExtension;
} }
return $file; return $file;
} }
......
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