Exemple #1
0
 /**
  * 运行对应的控制器
  *
  * @return void
  */
 public final function runAppController()
 {
     //检测csrf跨站攻击
     Secure::checkCsrf(Config::get('check_csrf'));
     // 关闭GPC过滤 防止数据的正确性受到影响 在db层防注入
     if (get_magic_quotes_gpc()) {
         Secure::stripslashes($_GET);
         Secure::stripslashes($_POST);
         Secure::stripslashes($_COOKIE);
         Secure::stripslashes($_REQUEST);
         //在程序中对get post cookie的改变不影响 request的值
     }
     //session保存方式自定义
     if (Config::get('session_user')) {
         Session::init();
     } else {
         ini_get('session.auto_start') || session_start();
         //自动开启session
     }
     header('Cache-control: ' . Config::get('http_cache_control'));
     // 页面缓存控制
     //如果有子类中有init()方法 执行Init() eg:做权限控制
     if (method_exists($this, "init")) {
         $this->init();
     }
     //根据动作去找对应的方法
     $method = Route::$urlParams['action'];
     if (method_exists($this, $method)) {
         $this->{$method}();
     } elseif ($GLOBALS['debug']) {
         Cml::montFor404Page();
         throwException(Lang::get('_ACTION_NOT_FOUND_', Route::$urlParams['action']));
     } else {
         Cml::montFor404Page();
         Response::show404Page();
     }
 }
Exemple #2
0
 /**
  * URL组装 支持不同URL模式
  * eg: \Cml\Http\Response::url('Home/Blog/cate/id/1')
  *
  * @param string $url URL表达式 路径/控制器/操作/参数1/参数1值/.....
  * @param int $echo 是否输出  1输出 0 return
  *
  * @return string
  */
 public static function url($url = '', $echo = 1)
 {
     $return = '';
     // 解析URL
     if (empty($url)) {
         throw new \InvalidArgumentException(Lang::get('_NOT_ALLOW_EMPTY_', 'url'));
         //'U方法参数出错'
     }
     // URL组装
     $delimiter = Config::get('url_pathinfo_depr');
     $url = ltrim($url, '/');
     $url = implode($delimiter, explode('/', $url));
     if (Config::get('url_model') == 1) {
         $return = $_SERVER['SCRIPT_NAME'] . '/' . $url;
     } elseif (Config::get('url_model') == 2) {
         $return = Cml::getContainer()->make('cml_route')->getSubDirName() . $url;
     } elseif (Config::get('url_model') == 3) {
         $return = $_SERVER['SCRIPT_NAME'] . '?' . Config::get('var_pathinfo') . '=/' . $url;
     }
     $return .= Config::get('url_model') == 2 ? Config::get('url_html_suffix') : '';
     $return = Secure::filterScript($return);
     if ($echo === 1) {
         echo $return;
     } else {
         return $return;
     }
     return '';
 }
Exemple #3
0
 /**
  * 渲染模板获取内容 调用内置的模板引擎显示方法,
  *
  * @param string $templateFile 指定要调用的模板文件 默认为空 由系统自动定位模板文件
  * @param bool $inOtherApp 是否为载入其它应用的模板
  *
  * @return string
  */
 public function fetch($templateFile = '', $inOtherApp = false)
 {
     if (Config::get('form_token')) {
         Secure::setToken();
     }
     if (!empty($this->args)) {
         extract($this->args, EXTR_PREFIX_SAME, "xxx");
         $this->args = array();
     }
     ob_start();
     require $this->getFile($this->initBaseDir($templateFile, $inOtherApp));
     return ob_get_clean();
 }
Exemple #4
0
 /**
  * URL组装 支持不同URL模式
  * eg: \Cml\Http\Response::url('Home/Blog/cate/id/1')
  *
  * @param string $url URL表达式 路径/控制器/操作/参数1/参数1值/.....
  * @param int $echo 是否输出  1输出 0 return
  *
  * @return string
  */
 public static function url($url = '', $echo = 1)
 {
     $return = '';
     // 解析URL
     empty($url) && \Cml\throwException(Lang::get('_CML_ERROR_'));
     //'U方法参数出错'
     // URL组装
     $delimiter = Config::get('url_pathinfo_depr');
     $url = ltrim($url, '/');
     $url = implode($delimiter, explode('/', $url));
     if (Config::get('url_model') == 1) {
         $return = $_SERVER['SCRIPT_NAME'] . '/' . $url;
     } elseif (Config::get('url_model') == 2) {
         $return = Route::$urlParams['root'] . $url;
     } elseif (Config::get('url_model') == 3) {
         $return = $_SERVER['SCRIPT_NAME'] . '?' . Config::get('var_pathinfo') . '=/' . $url;
     }
     $return .= Config::get('url_model') == 2 ? Config::get('url_html_suffix') : '';
     $return = Secure::filterScript($return);
     if ($echo === 1) {
         echo $return;
     } else {
         return $return;
     }
     return '';
 }