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']) {
         Alpha::montFor404Page();
         throwException(Lang::get('_ACTION_NOT_FOUND_', Route::$urlParams['action']));
     } else {
         Alpha::montFor404Page();
         Response::show404Page();
     }
 }
Exemple #2
0
 /**
  * URL组装 支持不同URL模式
  * eg: \Foundation\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) && \Foundation\throwException(Lang::get('_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 '';
 }