Example #1
0
 public static function run()
 {
     self::init();
     //启动数据组件
     $Capsule = new Capsule();
     $Capsule->addConnection(config::get('database'));
     // 使用DB
     $Capsule->bootEloquent();
     $controller = sf::getController(router::getController());
     try {
         method_exists($controller, "load") && $controller->load();
         if (!method_exists($controller, router::getMethod())) {
             throw new sfException(sprintf(lang::get("Call to undefined method %s::%s"), get_class($controller), router::getMethod()));
         }
         $controller->{router::getMethod()}();
         method_exists($controller, "shutdown") && $controller->shutdown();
     } catch (sfException $e) {
         method_exists($controller, "shutdown") && $controller->shutdown();
         $e->halt();
     }
 }
Example #2
0
 public static function create_routes($uri)
 {
     $router = array_flip((array) config::get("router.rule"));
     $uri = trim($uri, "/");
     if (isset($router[$uri])) {
         return $router[$uri];
     }
     foreach ((array) $router as $key => $val) {
         $key = preg_replace('#\\$+\\d{1,2}#', '([^/]+)', $key);
         if (preg_match_all('#^' . $key . '$#', $uri, $out)) {
             $_val = preg_split('#\\([^_\\(\\)]*\\)#', $val);
             for ($i = 0, $n = count($_val); $i < $n; $i++) {
                 $str .= $_val[$i] . $out[$i + 1][0];
             }
             return $str;
         }
     }
     return $uri;
 }