Skip to content

Commit 8be5de9

Browse files
committed
Minor refactor in how paths are checked, so that fallback extensions are checked only when all paths fail, instead of for each path. Refs #49
1 parent 2dca77c commit 8be5de9

File tree

1 file changed

+9
-10
lines changed

1 file changed

+9
-10
lines changed

cake/libs/view/view.php

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -805,14 +805,13 @@ function _getViewFileName($name = null) {
805805
}
806806

807807
$paths = $this->_paths(Inflector::underscore($this->plugin));
808-
809-
foreach ($paths as $path) {
810-
if (file_exists($path . $name . $this->ext)) {
811-
return $path . $name . $this->ext;
812-
} elseif (file_exists($path . $name . '.ctp')) {
813-
return $path . $name . '.ctp';
814-
} elseif (file_exists($path . $name . '.thtml')) {
815-
return $path . $name . '.thtml';
808+
809+
$exts = array($this->ext, '.ctp', '.thtml');
810+
foreach ($exts as $ext) {
811+
foreach ($paths as $path) {
812+
if (file_exists($path . $name . $ext)) {
813+
return $path . $name . $ext;
814+
}
816815
}
817816
}
818817
$defaultPath = $paths[0];
@@ -848,8 +847,8 @@ function _getLayoutFileName($name = null) {
848847
$file = 'layouts' . DS . $subDir . $name;
849848

850849
$exts = array($this->ext, '.ctp', '.thtml');
851-
foreach ($paths as $path) {
852-
foreach ($exts as $ext) {
850+
foreach ($exts as $ext) {
851+
foreach ($paths as $path) {
853852
if (file_exists($path . $file . $ext)) {
854853
return $path . $file . $ext;
855854
}

0 commit comments

Comments
 (0)