Beispiel #1
0
 /**
  * Construct view script path
  *
  * Used by render() and display to determine the path to the view script.
  *
  * @param string $action
  *            Defaults to action registered in request object
  *            
  * @return string
  * @throws InvalidArgumentException with bad $action
  */
 protected function getViewScript($action = null)
 {
     // 如果已经手动设置,则使用自己的设置
     if (!empty($this->_script)) {
         $script = $this->_script;
     } else {
         $request = $this->getRequest();
         if (null === $action) {
             $action = $request->getActionName();
         } elseif (!is_string($action)) {
             throw new Yaf_Exception('Invalid action for view rendering');
         }
         $action = str_replace('_', DIRECTORY_SEPARATOR, strtolower($action));
         $script = $action . '.' . Yaf_G::YAF_DEFAULT_VIEW_EXT;
         $controller = $request->getControllerName();
         if ($controller != null) {
             $controller = str_replace('_', DIRECTORY_SEPARATOR, $controller);
         }
         $script = $request->getModuleName() . DIRECTORY_SEPARATOR . $controller . DIRECTORY_SEPARATOR . $script;
     }
     $script = trim($script, DIRECTORY_SEPARATOR);
     $script = Yaf_G::getViewPath() . DIRECTORY_SEPARATOR . $script;
     if (!file_exists($script)) {
         throw new Yaf_Exception('View file 【' . $script . '】 not found!');
     }
     return $script;
 }
Beispiel #2
0
 /**
  * 初始化View
  *
  * @param string $templates_dir
  * @param unknown $options
  * @return Yaf_View_Interface
  */
 public function initView($templates_dir = null, $options = array())
 {
     if ($this->_view == null) {
         if (empty($templates_dir)) {
             $templates_dir = Yaf_G::getViewPath();
         }
         $this->_view = new Yaf_View_Simple($templates_dir, $options);
     }
     return $this->_view;
 }
Beispiel #3
0
 /**
  * Finds a view script from the available directory.
  *
  * @param string $name
  *            The base name of the script.
  *            
  * @return void
  */
 protected function _script($name)
 {
     if (preg_match('#\\.\\.[\\\\/]#', $name)) {
         throw new Yaf_Exception('Requested scripts may not include parent ' . 'directory traversal ("../", "..\\" notation)');
     }
     $tpl_dir = Yaf_G::getViewPath();
     if ($tpl_dir == '') {
         throw new Yaf_Exception('Could not determine the view script path, ' . 'you should call Yaf_View_Simple::setScriptPath to specific it');
     }
     if (Yaf_G::isAbsolutePath($name) && is_readable($name)) {
         return $name;
     } elseif (is_readable($tpl_dir . DIRECTORY_SEPARATOR . $name)) {
         return $tpl_dir . DIRECTORY_SEPARATOR . $name;
     }
     throw new Yaf_Exception("Unable to find template " . $tpl_dir . DIRECTORY_SEPARATOR . $name);
 }