Commit a1f7f8bc by Qiang Xue

Fixes #1335: support view extension fallback

parent 9d57b40b
......@@ -417,9 +417,13 @@ class Controller extends Component implements ViewContextInterface
$file = $module->getLayoutPath() . DIRECTORY_SEPARATOR . $layout;
}
if (pathinfo($file, PATHINFO_EXTENSION) === '') {
$file .= $view->defaultExtension;
}
if (pathinfo($file, PATHINFO_EXTENSION) !== '') {
return $file;
}
$path = $file . '.' . $view->defaultExtension;
if ($view->defaultExtension !== 'php' && !is_file($path)) {
$path = $file . '.php';
}
return $path;
}
}
......@@ -67,7 +67,7 @@ class View extends Component
/**
* @var string the default view file extension. This will be appended to view file names if they don't have file extensions.
*/
public $defaultExtension = '.php';
public $defaultExtension = 'php';
/**
* @var Theme|array the theme object or the configuration array for creating the theme object.
* If not set, it means theming is not enabled.
......@@ -171,7 +171,14 @@ class View extends Component
}
}
return pathinfo($file, PATHINFO_EXTENSION) === '' ? $file . $this->defaultExtension : $file;
if (pathinfo($file, PATHINFO_EXTENSION) !== '') {
return $file;
}
$path = $file . '.' . $this->defaultExtension;
if ($this->defaultExtension !== 'php' && !is_file($path)) {
$path = $file . '.php';
}
return $path;
}
/**
......
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