Example #1
0
 public static function start()
 {
     //美化url
     if (!empty($_SERVER['PATH_INFO'])) {
         $rewrite = explode("/", trim($_SERVER['PATH_INFO'], "/"));
         if (count($rewrite) >= 3) {
             self::$module = $rewrite[0];
             self::$class = $rewrite[1];
             self::$function = $rewrite[2];
         }
     }
     isset($_GET['m']) ? self::$module = trim($_GET['m']) : self::$module;
     isset($_GET['c']) ? self::$class = trim($_GET['c']) : self::$class;
     isset($_GET['f']) ? self::$function = trim($_GET['f']) : self::$function;
     //扩展名分析
     if (!empty(self::$function)) {
         if (strrpos(self::$function, '.htmlx') !== false) {
             self::$function = str_replace('.htmlx', '', self::$function);
         }
     }
     //内部php调用
     if (isset($_SERVER['argv'][1])) {
         if ($_SERVER['argv'][1] == 'task') {
             Router::Controller("Task." . $_SERVER['argv'][2])->{$_SERVER}['argv'][3]();
             exit;
         }
     }
     //载入中间件
     Router::getClass("\\AppMain\\middleware\\HttpMiddleware");
     //载入路由
     Router::router();
 }
Example #2
0
 /**
  * 调用Api的Controller生成view
  * @param string|array $class Controller位置
  * @param string|array $function
  * @param array 参数 
  * @example $this->ApiView('Api.Test','test123',['234234','23434']);
  * @example $this->ApiView(['Api.Test','Api.Test'],['test123','test1234'],[['234234','23434'],['ffff']]);
  */
 protected function ApiView($class, $function, $params = [])
 {
     if (is_string($class)) {
         $dataClass = Router::Controller($class, true);
         call_user_func_array([$dataClass, $function], (array) $params);
     } else {
         foreach ($class as $key => $v) {
             $dataClass = Router::Controller($v, true, true, $function[$key]);
             $mutiParams = empty($params) ? [] : $params[$key];
             call_user_func_array([$dataClass, $function[$key]], (array) $mutiParams);
         }
     }
     $this->View();
 }
Example #3
0
    //echo $_SERVER['REQUEST_URI'];
    require_once 'conf.php';
    require_once 'router.php';
    $req_uri = filter_input(INPUT_SERVER, 'REQUEST_URI');
    //echo $req_uri;
    //$post_get = (filter_input_array(INPUT_POST) ?: array()) + (filter_input_array(INPUT_GET) ?: array());
    $post = filter_input_array(INPUT_POST);
    if (isset($post)) {
        foreach ($post as $k => $zzz) {
            tester::TEST($k . "=>" . $zzz);
        }
    }
    /*    if (isset($_POST["test_zzz"]))
            tester::TEST("____hura");
        else
            tester::TEST("____QQQ");*/
    $router = new Router($req_uri, $post);
    $ctrl = $router->Controller() ?: DEFAULT_CTRL;
    if (strtolower($ctrl) == 'index.php') {
        $ctrl = DEFAULT_CTRL;
    }
    $ctrl_php = 'controller_' . strtolower($ctrl) . '.php';
    $ctrl_class = 'Controller' . $ctrl;
    $action = $router->Action() ?: DEFAULT_ACTION;
    $params = $router->Params();
    require_once DIR_CTRL . $ctrl_php;
    $controller = new $ctrl_class();
    $controller->{$action}($params);
} catch (Exception $ex) {
    echo 'Error!!!' . $ex;
}
Example #4
0
<?php

define('__ROOT__', dirname(__FILE__) . '/');
require_once 'config.php';
require_once 'router.php';
Router::Start();
session_start();
$router = new Router();
$controller = $router->Controller();
$ctrl_class = $router->CtrlClass();
$action = $router->Action();
$params = $router->Params();
require_once DIR_CTRL . $controller;
$controller = new $ctrl_class();
$controller->{$action}($params);