Esempio n. 1
0
 protected static function _router($controllers_path, $path)
 {
     if ($path && is_string($path)) {
         // 字符串 myweb/home/index/a/b
         $path = explode('/', trim($path, '/'));
     } elseif ($path && is_array($path)) {
         // 数组 array( 'myweb', 'home', 'index', 'a', 'b' )
     }
     //是否带文件目录
     if (CONTROLLERS_USERDIR && $path) {
         self::$_fileDir = array_shift($path);
     }
     self::_fileClassMethod($path);
     //查找控制器
     $class_name = self::$_class . ".php";
     $dir_path = '/';
     $arr_name = '_controllers';
     $rs = self::_findClass($controllers_path, $class_name, $arr_name, $dir_path);
     if (!$rs) {
         if (self::$_class !== 'favicon.ico') {
             Log::write2("controller找不到类:" . self::$_class, 'router');
         }
         return false;
     }
     $controll = new self::$_class();
     //执行类方法
     call_user_func_array(array($controll, self::$_method), self::$_args);
 }
Esempio n. 2
0
 protected static function _findClass($root_path, $class_name, $arr_name, $dir_path)
 {
     ${$arr_name} = self::${$arr_name};
     if (!${$arr_name}) {
         Log::write2("找不到{$arr_name目录}", 'router');
         return false;
     }
     //如果路径带文件夹
     if (self::$_fileDir && $arr_name === '_controllers') {
         if (!in_array(self::$_fileDir, ${$arr_name})) {
             Log::write2($arr_name . "目录找不到" . self::$_fileDir, 'router');
             self::$_fileDir = null;
             return false;
         }
     }
     if (${$arr_name}) {
         foreach (${$arr_name} as $m) {
             $file_path = $root_path . $m . $dir_path . $class_name;
             if (is_file($file_path)) {
                 require_once $file_path;
                 return true;
             }
         }
     }
     return false;
 }