예제 #1
0
 public static function boot()
 {
     /**
      * 注册一个路由器,对当前请求的uri进行重写
      */
     Hi_Router::add('/thisisatest\\/(.+?)\\/([^\\/]+)\\/?/', '/$1/$2', $params = array('x' => '$2', 'y' => '$3'));
 }
예제 #2
0
 /**
  * 根据URI获取逻辑处理类以及方法
  *
  * 最理想的调用格式为 do=控制器命名空间(参数1)/控制器(参数2)/控制器方法(参数3)
  * 如果do == null,控制器命名空间 = '',控制器 = index, 控制器方法 = index
  * 如果do只有一个参数,控制器命名空间 = '',控制器 = index, 控制器方法 = 参数1
  * 如果do有两个参数,如果 参数1 对应的 控制器 存在,参数2 就是控制器方法;
  * 如果 参数1 对应的 控制器 不存在,参数1为控制器空间,参数2 控制器,控制器方法为 index
  *
  * @return unknown
  */
 private function _setAction($uri = null)
 {
     //扫描自定义的路由器
     $routedUri = Hi_Router::route($uri);
     if (!empty($routedUri)) {
         $uri = $routedUri;
     }
     if (empty($uri)) {
         $uri = $this->_getUriFromRequest();
     }
     //去掉开头和结尾的斜线
     $uri = preg_replace('/\\/$/', '', $uri);
     $uri = preg_replace('/^\\//', '', $uri);
     if (empty($uri) || !preg_match('/^[a-z]+(\\/[a-z][a-z0-9]+\\/?)*$/i', $uri)) {
         $this->_class = 'Action_Index';
         $this->_action = 'Index';
         return true;
     }
     $doArray = explode('/', $uri);
     $act = 'index';
     while ($doArray) {
         $ss = implode(' ', $doArray);
         $ss = ucwords($ss);
         $class = str_replace(' ', '_', $ss);
         $class = 'Action_' . $class;
         if (class_exists($class)) {
             $this->_class = $class;
             break;
         }
         if (class_exists($class . '_Index')) {
             $this->_class = $class . '_Index';
             break;
         }
         $act = array_pop($doArray);
     }
     $this->_action = $act;
     return true;
 }