Browse Source

Fixes #1335: support view extension fallback

tags/2.0.0-beta
Qiang Xue 11 years ago
parent
commit
a1f7f8bcbe
  1. 10
      framework/yii/base/Controller.php
  2. 11
      framework/yii/base/View.php

10
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;
}
$path = $file . '.' . $view->defaultExtension;
if ($view->defaultExtension !== 'php' && !is_file($path)) {
$path = $file . '.php';
}
return $path;
}
}

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

Loading…
Cancel
Save