Browse Source

Merge pull request #7268 from NaranjaWeb/#7240

#7240 Extract one line which underscores name of template file into a seperate method
José Lorenzo Rodríguez 10 years ago
parent
commit
70e411bad4
1 changed files with 16 additions and 3 deletions
  1. 16 3
      src/View/View.php

+ 16 - 3
src/View/View.php

@@ -1005,8 +1005,10 @@ class View implements EventDispatcherInterface
 
     /**
      * Returns filename of given action's template file (.ctp) as a string.
-     * CamelCased action names will be under_scored! This means that you can have
-     * LongActionNames that refer to long_action_names.ctp views.
+     * CamelCased action names will be under_scored by default.
+     * This means that you can have LongActionNames that refer to
+     * long_action_names.ctp views. You can change the inflection rule by
+     * overriding _inflectViewFileName.
      *
      * @param string|null $name Controller action to find template filename for
      * @return string Template filename
@@ -1031,7 +1033,7 @@ class View implements EventDispatcherInterface
         $name = str_replace('/', DS, $name);
 
         if (strpos($name, DS) === false && $name[0] !== '.') {
-            $name = $templatePath . $subDir . Inflector::underscore($name);
+            $name = $templatePath . $subDir . $this->_inflectViewFileName($name);
         } elseif (strpos($name, DS) !== false) {
             if ($name[0] === DS || $name[1] === ':') {
                 if (is_file($name)) {
@@ -1054,6 +1056,17 @@ class View implements EventDispatcherInterface
     }
 
     /**
+     * Change the name of a view template file into underscored format.
+     *
+     * @param string $name Name of file which should be inflected.
+     * @return string File name after conversion
+     */
+    protected function _inflectViewFileName($name)
+    {
+        return Inflector::underscore($name);
+    }
+
+    /**
      * Check that a view file path does not go outside of the defined template paths.
      *
      * Only paths that contain `..` will be checked, as they are the ones most likely to