Browse Source

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

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
1fe7f5aaf8
  1. 23
      framework/yii/base/Controller.php

23
framework/yii/base/Controller.php

@ -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
/** /**
* 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;
} }

Loading…
Cancel
Save