function _getViewFileName($name = null)
 {
     if (!is_array($name)) {
         return parent::_getViewFileName($name);
     } else {
         //debug($name);
         //die();
         $subDir = null;
         if (!is_null($this->subDir)) {
             $subDir = $this->subDir . DS;
         }
         $paths = array();
         foreach ($name as $name) {
             $name = str_replace('/', DS, $name);
             if (strpos($name, DS) === false && $name[0] !== '.') {
                 $name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
             } elseif (strpos($name, DS) !== false) {
                 if ($name[0] === DS || $name[1] === ':') {
                     if (is_file($name)) {
                         return $name;
                     }
                     $name = trim($name, DS);
                 } else {
                     if ($name[0] === '.') {
                         $name = substr($name, 3);
                     } else {
                         $name = $this->viewPath . DS . $subDir . $name;
                     }
                 }
             }
             $paths = array_merge($paths, $this->_paths(Inflector::underscore($this->plugin)));
             foreach ($paths as $path) {
                 if (file_exists($path . $name . $this->ext)) {
                     return $path . $name . $this->ext;
                 } elseif (file_exists($path . $name . '.ctp')) {
                     return $path . $name . '.ctp';
                 } elseif (file_exists($path . $name . '.thtml')) {
                     return $path . $name . '.thtml';
                 }
             }
         }
         $defaultPath = $paths[0];
         if ($this->plugin) {
             $pluginPaths = Configure::read('pluginPaths');
             foreach ($paths as $path) {
                 if (strpos($path, $pluginPaths[0]) === 0) {
                     $defaultPath = $path;
                     break;
                 }
             }
         }
         return $this->_missingView($defaultPath . $name . $this->ext, 'missingView');
     }
 }
 /**
  * _getViewFileName
  *
  * Search relative and absolute (to the view folder) paths for which view to use for the given api call
  *
  * @throws \MissingViewException
  * @param mixed $name
  * @return void
  */
 protected function _getViewFileName($name = null)
 {
     $name = $name ?: $this->view;
     $this->subDir = $this->apiFormat;
     try {
         return parent::_getViewFileName($name);
     } catch (MissingViewException $exception) {
     }
     try {
         return parent::_getViewFileName(DS . $this->apiFormat . DS . $name);
     } catch (MissingViewException $e) {
         if (isset($this->viewVars['success']) || isset($this->viewVars['data'])) {
             return parent::_getViewFileName(DS . $this->apiFormat . DS . 'fallback_template');
         }
         throw $e;
     }
 }
Example #3
0
 /**
  * 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.
  *
  * @param string $name Controller action to find template filename for
  * @return string Template filename
  * @throws MissingViewException when a view file could not be found.
  */
 protected function _getViewFileName($name = null)
 {
     $subDir = null;
     if (!is_null($this->subDir)) {
         $subDir = $this->subDir . DS;
     }
     if ($name === null) {
         $name = $this->view;
     }
     // CUSTOMIZE ADD 2012/04/11 ryuring
     // プレフィックスが設定されている場合は、プレフィックスを除外する
     // >>>
     $prefix = '';
     if (!empty($this->request->params['prefix'])) {
         $prefix = $this->request->params['prefix'];
     }
     if ($prefix && preg_match('/^' . $prefix . '_/', $name)) {
         $name = str_replace($prefix . '_', '', $name);
     } elseif (preg_match('/^admin_/', $name)) {
         // プレフィックスをadminとしてすり替え
         $name = str_replace('admin_', '', $name);
     }
     // >>>
     $name = str_replace('/', DS, $name);
     list($plugin, $name) = $this->pluginSplit($name);
     // CUSTOMIZE ADD 2012/04/11 ryuring
     // CakeErrorの場合はサブフォルダを除外
     // >>>
     if ($this->name == 'CakeError' && $this->viewPath == 'Errors') {
         $subDir = $this->subDir;
         $this->subDir = null;
         $fileName = parent::_getViewFileName($name);
         $this->subDir = $subDir;
         return $fileName;
     }
     // <<<
     // CUSTOMIZE ADD 2013/08/25 ryuring
     // イベントを追加
     // >>>
     $event = $this->dispatchEvent('beforeGetViewFileName', array('name' => $name), array('class' => '', 'plugin' => ''));
     if ($event !== false) {
         $name = $event->result === null || $event->result === true ? $event->data['name'] : $event->result;
     }
     $event = $this->dispatchEvent('beforeGetViewFileName', array('name' => $name));
     if ($event !== false) {
         $name = $event->result === null || $event->result === true ? $event->data['name'] : $event->result;
     }
     // <<<
     if (strpos($name, DS) === false && $name[0] !== '.') {
         // CUSTOMIZE MODIFY 2016/06/01 ryuring
         // サブフォルダが存在しない場合にはサブフォルダなしのパスを利用するようにした
         // >>>
         //$name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
         // ---
         $name = array($this->viewPath . DS . $subDir . Inflector::underscore($name), $this->viewPath . DS . Inflector::underscore($name));
         // <<<
     } elseif (strpos($name, DS) !== false) {
         if ($name[0] === DS || $name[1] === ':') {
             if (is_file($name)) {
                 return $name;
             }
             $name = trim($name, DS);
         } elseif ($name[0] === '.') {
             $name = substr($name, 3);
             // CUSTOMIZE MODIFY 2013/08/21 ryuring
             // サブフォルダが適用されない為調整
             // CUSTOMIZE MODIFY 2016/06/01 ryuring
             // サブフォルダが存在しない場合にはサブフォルダなしのパスを利用するようにした
             // >>>
             /*
             } elseif (!$plugin || $this->viewPath !== $this->name) {
             	$name = $this->viewPath . DS . $subDir . $name;
             */
             // ---
         } else {
             $name = array($this->viewPath . DS . $subDir . $name, $this->viewPath . DS . $name);
             // <<<
         }
     }
     $paths = $this->_paths($plugin);
     $exts = $this->_getExtensions();
     // CUSTOMIZE MODIFY 2012/04/11 ryuring
     // 拡張子優先順位よりもパスの優先順位を優先する仕様に変更
     // CUSTOMIZE MODIFY 2016/06/01 ryuring
     // サブフォルダが存在しない場合にはサブフォルダなしのパスを利用するようにした
     // >>>
     /*
     foreach ($exts as $ext) {
     	foreach ($paths as $path) {
     		if (file_exists($path . $name . $ext)) {
     			return $path . $name . $ext;
       		}
       	}
     }
     */
     // ---
     if (is_array($name)) {
         $names = $name;
     } else {
         $names[] = $name;
     }
     foreach ($names as $name) {
         foreach ($paths as $path) {
             foreach ($exts as $ext) {
                 if (file_exists($path . $name . $ext)) {
                     if ($ext == '.ctp') {
                         trigger_error('ビューテンプレートの拡張子 .ctp は非推奨です。.php を利用してください。<br />' . $path . $name . $ext, E_USER_WARNING);
                     }
                     return $path . $name . $ext;
                 }
             }
         }
     }
     // <<<
     $defaultPath = $paths[0];
     if ($this->plugin) {
         $pluginPaths = App::path('plugins');
         foreach ($paths as $path) {
             if (strpos($path, $pluginPaths[0]) === 0) {
                 $defaultPath = $path;
                 break;
             }
         }
     }
     throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
 }
Example #4
0
 /**
  * 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.
  *
  * @param string $name Controller action to find template filename for
  * @return string Template filename
  * @throws MissingViewException when a view file could not be found.
  */
 protected function _getViewFileName($name = null)
 {
     $subDir = null;
     if (!is_null($this->subDir)) {
         $subDir = $this->subDir . DS;
     }
     if ($name === null) {
         $name = $this->view;
     }
     // CUSTOMIZE ADD 2012/04/11 ryuring
     // プレフィックスが設定されている場合は、プレフィックスを除外する
     // >>>
     $prefix = '';
     if (!empty($this->request->params['prefix'])) {
         $prefix = $this->request->params['prefix'];
     }
     if ($prefix && preg_match('/^' . $prefix . '_/', $name)) {
         $name = str_replace($prefix . '_', '', $name);
     } elseif (preg_match('/^admin_/', $name)) {
         // プレフィックスをadminとしてすり替え
         $name = str_replace('admin_', '', $name);
     }
     // >>>
     $name = str_replace('/', DS, $name);
     list($plugin, $name) = $this->pluginSplit($name);
     // CUSTOMIZE ADD 2012/04/11 ryuring
     // CakeErrorの場合はサブフォルダを除外
     // >>>
     if ($this->name == 'CakeError' && $this->viewPath == 'Errors') {
         $subDir = $this->subDir;
         $this->subDir = null;
         $fileName = parent::_getViewFileName($name);
         $this->subDir = $subDir;
         return $fileName;
     }
     // <<<
     // CUSTOMIZE ADD 2013/08/25 ryuring
     // イベントを追加
     // >>>
     $event = $this->dispatchEvent('beforeGetViewFileName', array('name' => $name), array('class' => '', 'plugin' => ''));
     if ($event !== false) {
         $name = $event->result === null || $event->result === true ? $event->data['name'] : $event->result;
     }
     $event = $this->dispatchEvent('beforeGetViewFileName', array('name' => $name));
     if ($event !== false) {
         $name = $event->result === null || $event->result === true ? $event->data['name'] : $event->result;
     }
     // <<<
     // CUSTOMIZE ADD 2012/10/11 ryuring
     // モバイルの固定ページの場合、PCの固定ページと連動する場合は、サブフォルダを空に設定
     // >>>
     $siteConfig = $this->getVar('siteConfig');
     if ($this->name == 'Pages' && preg_match('/(.+)_display$/', $this->request->action, $maches)) {
         $Page = ClassRegistry::getObject('Page');
         $url = '/' . implode('/', $this->params['pass']);
         if ($Page->isLinked($maches[1], $url)) {
             $subDir = '';
         }
     }
     // <<<
     if (strpos($name, DS) === false && $name[0] !== '.') {
         $name = $this->viewPath . DS . $subDir . Inflector::underscore($name);
     } elseif (strpos($name, DS) !== false) {
         if ($name[0] === DS || $name[1] === ':') {
             if (is_file($name)) {
                 return $name;
             }
             $name = trim($name, DS);
         } elseif ($name[0] === '.') {
             $name = substr($name, 3);
             // CUSTOMIZE MODIFY 2013/08/21 ryuring
             // サブフォルダが適用されない為調整
             // >>>
             //} elseif (!$plugin || $this->viewPath !== $this->name) {
             // ---
         } else {
             // <<<
             $name = $this->viewPath . DS . $subDir . $name;
         }
     }
     $paths = $this->_paths($plugin);
     $exts = $this->_getExtensions();
     // CUSTOMIZE MODIFY 2012/04/11 ryuring
     // 拡張子優先順位よりもパスの優先順位を優先する仕様に変更
     // @deprecated .php への移行を推奨
     // >>>
     /* foreach ($exts as $ext) {
     	  foreach ($paths as $path) {
     	  if (file_exists($path . $name . $ext)) {
     	  return $path . $name . $ext;
     	  }
     	  }
     	  } */
     // ---
     foreach ($paths as $path) {
         foreach ($exts as $ext) {
             if (file_exists($path . $name . $ext)) {
                 if ($ext == '.ctp') {
                     trigger_error('ビューテンプレートの拡張子 .ctp は非推奨です。.php を利用してください。<br />' . $path . $name . $ext, E_USER_WARNING);
                 }
                 return $path . $name . $ext;
             }
         }
     }
     // <<<
     $defaultPath = $paths[0];
     if ($this->plugin) {
         $pluginPaths = App::path('plugins');
         foreach ($paths as $path) {
             if (strpos($path, $pluginPaths[0]) === 0) {
                 $defaultPath = $path;
                 break;
             }
         }
     }
     throw new MissingViewException(array('file' => $defaultPath . $name . $this->ext));
 }