示例#1
0
 /**
  * 每次初始化的执行加载和初始化
  * @author wave
  */
 public function __construct()
 {
     $params = self::getUrl();
     //獲取URL參數數組
     $request = array();
     //URL的参数
     $num = 0;
     //动态URL访问
     //动态的URL的路由器
     if (!isset($params['rewirte'])) {
         $params[M] = isset($params[M]) ? $params[M] : M_INDEX;
         $params[A] = isset($params[A]) ? $params[A] : A_INDEX;
         $controller = $params[M] . 'Controller.php';
         $action = $params[A];
     } else {
         //伪静态的URL的路由器
         if (!empty($params)) {
             unset($params['rewirte']);
             $params['0'] = isset($params['0']) ? $params['0'] : M_INDEX;
             $params['1'] = isset($params['1']) ? $params['1'] : A_INDEX;
             if (strpos($params['1'], '?') !== false) {
                 $str = substr($params['1'], strpos($params['1'], '?'));
                 $params['1'] = str_replace($str, '', $params['1']);
             }
             $controller = $params['0'] . 'Controller.php';
             $action = $params['1'];
             $num = 1;
         }
     }
     //引入控制器,并初始化控制器
     if (!empty($action) && !empty($controller)) {
         if (load($controller, APP_PATH . DS . ROOT_CONTROLLER)) {
             $controller_name = isset($params[M]) ? $params[M] : $params['0'];
             $xb = Xbphp::run_cache($controller_name . 'Controller');
         }
         if (isset($xb) && method_exists($xb, $action)) {
             $paramArr = self::replaceArr(array($controller_name, $action), '', $params);
             $request = isset($params['params']) ? $params['params'] : $paramArr;
             $route = load('route.php', APP_PATH . DS . DATABASE . DS);
             //加载路由规则
             if (!empty($num) && isset($route['rewirte'][rtrim($controller, 'Controller.php')][$action])) {
                 $request = implode('/', $request);
                 $this->route('rewirte', $request, $route, $controller, $action);
             }
             //动态url规则
             if (empty($num) && isset($route['trends'][rtrim($controller, 'Controller.php')][$action])) {
                 $this->route('trends', $request, $route, $controller, $action);
             }
             call_user_func_array(array($xb, $action), $request);
         } else {
             load('404.tpl', ROOT_PATH . DS . ROOT_ERROR . DS . 'tpl');
             exit;
         }
     } else {
         load('404.tpl', ROOT_PATH . DS . ROOT_ERROR . DS . 'tpl');
         exit;
     }
     //打开DEUG
     if (DEBUG) {
         self::debug();
     }
 }
示例#2
0
 /**
  * 初始化视图类
  * @return Object
  * @author wave
  */
 private function views()
 {
     if (class_exists('view')) {
         $this->view = Xbphp::run_cache('view');
     }
 }
示例#3
0
        $arr = array_values(array_filter(explode('/', ltrim(strip_tags($_SERVER['REQUEST_URI']), '/'))));
        if (isset($arr['0']) && strtolower($arr['0']) == strtolower(basename(ROOT))) {
            array_splice($arr, 0, 1);
        }
        if (!empty($arr)) {
            if (isset($arr['0']) && file_exists(ROOT . DS . $arr['0'] . DS)) {
                define('APP_PATH', $arr['0']);
            }
        }
    }
}
if (!defined('APP_PATH') || APP_PATH == NULL) {
    define('APP_PATH', $root_path);
}
//判断目录是否存在
if (!defined('APP_PATH') || !file_exists(ROOT . DS . APP_PATH . DS)) {
    load('404.tpl', ROOT_PATH . DS . ROOT_ERROR . DS . 'tpl');
    exit;
}
//如果加载自定义配置文件不成功,则加载系统默认的配置文件
if (!load('configure.inc.php', APP_PATH . DS . DATABASE . DS)) {
    load('configure.inc.php', ROOT_PATH . DS . ROOT_CONF . DS);
}
load('defined.php', APP_PATH . DS . DATABASE . DS);
load('Autoloads.php', ROOT_PATH);
//自動加載文件,不加載靜態類文件
load('App.class.php', ROOT_PATH);
//路由与加载机制
//执行程序入口
Xbphp::run_cache('App');
示例#4
0
文件: view.php 项目: DenonHuang/xbphp
 /**
  * 获取smarty模版引擎
  * @author wave
  */
 private function _get_smarty()
 {
     load('Smarty.class.php', 'vendors/Smarty/libs');
     $this->smarty = Xbphp::run_cache('Smarty');
     $this->smarty->cache_dir = $this->root . CACHE . DS . TEMPLATES;
     $this->smarty->template_dir = $this->root . ROOT_VIEW . DS;
     $this->smarty->compile_dir = $this->root . CACHE . DS . TMP;
     $this->smarty->left_delimiter = $this->left_delimiter;
     $this->smarty->right_delimiter = $this->right_delimiter;
 }