From a1f7f8bcbed7c1d3c88b8e58ca7a6f016446138f Mon Sep 17 00:00:00 2001 From: Qiang Xue Date: Thu, 28 Nov 2013 23:58:14 -0500 Subject: [PATCH] Fixes #1335: support view extension fallback --- framework/yii/base/Controller.php | 10 +++++++--- framework/yii/base/View.php | 11 +++++++++-- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/framework/yii/base/Controller.php b/framework/yii/base/Controller.php index 42a2efc..72eb0c8 100644 --- a/framework/yii/base/Controller.php +++ b/framework/yii/base/Controller.php @@ -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; } - return $file; + $path = $file . '.' . $view->defaultExtension; + if ($view->defaultExtension !== 'php' && !is_file($path)) { + $path = $file . '.php'; + } + return $path; } } diff --git a/framework/yii/base/View.php b/framework/yii/base/View.php index fcfe31e..47650f0 100644 --- a/framework/yii/base/View.php +++ b/framework/yii/base/View.php @@ -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; } /**