Exemplo n.º 1
0
 /**
  * 自动定位模板文件
  * @access private
  * @param string $templateFile 文件名
  * @return string
  */
 private function parseTemplateFile($templateFile)
 {
     if ('' == $templateFile) {
         // 如果模板文件名为空 按照默认规则定位
         $templateFile = C('TEMPLATE_NAME');
     } elseif (false === strpos($templateFile, C('TMPL_TEMPLATE_SUFFIX'))) {
         // 解析规则为 模板主题:模块:操作 不支持 跨项目和跨分组调用
         $path = explode(':', $templateFile);
         $action = array_pop($path);
         $module = !empty($path) ? array_pop($path) : CONTROLLER_NAME;
         if (!empty($path)) {
             // 设置模板主题
             $path = dirname(THEME_PATH) . '/' . array_pop($path) . '/';
         } else {
             $path = THEME_PATH;
         }
         $templateFile = $path . $module . C('TMPL_FILE_DEPR') . $action . C('TMPL_TEMPLATE_SUFFIX');
     }
     if (!File::exists_case($templateFile)) {
         Debug::throw_exception(L('_TEMPLATE_NOT_EXIST_') . '[' . $templateFile . ']');
     }
     return $templateFile;
 }
Exemplo n.º 2
0
 /**
  * 魔术方法 有不存在的操作的时候执行
  *
  * @param string $method
  * @param array $args
  * @return mixed
  */
 public function __call($method, $args)
 {
     if (0 === strcasecmp($method, ACTION_NAME . C('ACTION_SUFFIX'))) {
         if (method_exists($this, '_empty')) {
             // 如果定义了_empty操作 则调用
             $this->_empty($method, $args);
         } elseif (File::exists_case(C('TEMPLATE_NAME'))) {
             // 检查是否存在默认模版 如果有直接输出模版
             $this->display();
         } elseif (function_exists('__hack_action')) {
             // hack 方式定义扩展操作
             __hack_action();
         } else {
             Debug::output(new Exception("Controller method 无效,\"" . ACTION_NAME . "\""));
         }
     } else {
         switch (strtolower($method)) {
             // 判断提交方式
             case 'ispost':
             case 'isget':
             case 'ishead':
             case 'isdelete':
             case 'isput':
                 return strtolower($_SERVER['REQUEST_METHOD']) == strtolower(substr($method, 2));
                 // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             // 获取变量 支持过滤和默认值 调用方式 $this->_post($key,$filter,$default);
             case '_get':
                 $input =& $_GET;
                 break;
             case '_post':
                 $input =& $_POST;
                 break;
             case '_put':
                 parse_str(file_get_contents('php://input'), $input);
                 break;
             case '_param':
                 switch ($_SERVER['REQUEST_METHOD']) {
                     case 'POST':
                         $input = $_POST;
                         break;
                     case 'PUT':
                         parse_str(file_get_contents('php://input'), $input);
                         break;
                     default:
                         $input = $_GET;
                 }
                 if (C('VAR_URL_PARAMS')) {
                     $params = $_GET[C('VAR_URL_PARAMS')];
                     $input = array_merge($input, $params);
                 }
                 break;
             case '_request':
                 $input =& $_REQUEST;
                 break;
             case '_session':
                 $input =& $_SESSION;
                 break;
             case '_cookie':
                 $input =& $_COOKIE;
                 break;
             case '_server':
                 $input =& $_SERVER;
                 break;
             case '_globals':
                 $input =& $GLOBALS;
                 break;
             default:
                 Debug::throw_exception(__CLASS__ . ':' . $method . L('_METHOD_NOT_EXIST_'));
         }
         if (!isset($args[0])) {
             // 获取全局变量
             $data = $input;
             // 由VAR_FILTERS配置进行过滤
         } elseif (isset($input[$args[0]])) {
             // 取值操作
             $data = $input[$args[0]];
             $filters = isset($args[1]) ? $args[1] : C('DEFAULT_FILTER');
             if ($filters) {
                 // 2012/3/23 增加多方法过滤支持
                 $filters = explode(',', $filters);
                 foreach ($filters as $filter) {
                     if (function_exists($filter)) {
                         $data = is_array($data) ? array_map($filter, $data) : $filter($data);
                         // 参数过滤
                     }
                 }
             }
         } else {
             // 变量默认值
             $data = isset($args[2]) ? $args[2] : NULL;
         }
         return $data;
     }
 }