Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixing issue where elements did not get .ctp as a fallback extension …

…unlike view and layout files.

Adding a protected method to get extensions, as it would be in 3 places now.
Added tests.
Fixes #1438
  • Loading branch information...
commit 0f4c90588d6e4b43c41ee2ce883303fe32ff14b1 1 parent f893e3b
@markstory markstory authored
Showing with 40 additions and 14 deletions.
  1. +25 −14 cake/libs/view/view.php
  2. +15 −0 cake/tests/cases/libs/view/view.test.php
View
39 cake/libs/view/view.php
@@ -372,11 +372,13 @@ function element($name, $params = array(), $loadHelpers = false) {
}
}
$paths = $this->_paths($plugin);
-
- foreach ($paths as $path) {
- if (file_exists($path . 'elements' . DS . $name . $this->ext)) {
- $file = $path . 'elements' . DS . $name . $this->ext;
- break;
+ $exts = $this->_getExtensions();
+ foreach ($exts as $ext) {
+ foreach ($paths as $path) {
+ if (file_exists($path . 'elements' . DS . $name . $ext)) {
+ $file = $path . 'elements' . DS . $name . $ext;
+ break;
+ }
}
}
@@ -862,10 +864,7 @@ function _getViewFileName($name = null) {
}
$paths = $this->_paths(Inflector::underscore($this->plugin));
- $exts = array($this->ext);
- if ($this->ext !== '.ctp') {
- array_push($exts, '.ctp');
- }
+ $exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . $name . $ext)) {
@@ -905,11 +904,8 @@ function _getLayoutFileName($name = null) {
}
$paths = $this->_paths(Inflector::underscore($this->plugin));
$file = 'layouts' . DS . $subDir . $name;
-
- $exts = array($this->ext);
- if ($this->ext !== '.ctp') {
- array_push($exts, '.ctp');
- }
+
+ $exts = $this->_getExtensions();
foreach ($exts as $ext) {
foreach ($paths as $path) {
if (file_exists($path . $file . $ext)) {
@@ -920,6 +916,21 @@ function _getLayoutFileName($name = null) {
return $this->_missingView($paths[0] . $file . $this->ext, 'missingLayout');
}
+
+/**
+ * Get the extensions that view files can use.
+ *
+ * @return array Array of extensions view files use.
+ * @access protected
+ */
+ function _getExtensions() {
+ $exts = array($this->ext);
+ if ($this->ext !== '.ctp') {
+ array_push($exts, '.ctp');
+ }
+ return $exts;
+ }
+
/**
* Return a misssing view error message
*
View
15 cake/tests/cases/libs/view/view.test.php
@@ -574,6 +574,21 @@ function testElementCache() {
}
/**
+ * test that ctp is used as a fallback file extension for elements
+ *
+ * @return void
+ */
+ function testElementCtpFallback() {
+ $View = new TestView($this->PostsController);
+ $View->ext = '.missing';
+ $element = 'test_element';
+ $expected = 'this is the test element';
+ $result = $View->element($element);
+
+ $this->assertEqual($expected, $result);
+ }
+
+/**
* testLoadHelpers method
*
* @access public
Please sign in to comment.
Something went wrong with that request. Please try again.