예제 #1
0
 function run()
 {
     try {
         $this->_filter->routeStartup();
         //路由开始
         $action = $this->_router->route();
         $action = $this->_filter->routeShutdown($action);
         //路由关闭
         $action = $this->_filter->dispatchStartup($action);
         //方法调度
         $method = $action->_method;
         $action->{$method}();
         $this->_filter->dispatchShutdown();
         //方法调度完成
         $action->response();
         $this->_filter->endReturn();
         //返回结果
     } catch (CException $e) {
         //异常处理
         if ($e->exceptionType == 'biz') {
             //业务逻辑异常--抛到业务层处理
             $actionclass = $e->exActionMethod . '_Action';
             $action = CFactory::instance($actionclass, $e->params, true, true);
             $method = $action->_method;
             $action->{$method}();
             $action->response();
             $this->_filter->endReturn();
             //返回结果
         } else {
             //核心异常--直接抛出异常
             throw new Exception($e);
         }
     }
 }
예제 #2
0
 function route($controller = null, $action = null, $method = null)
 {
     if (!$controller && !$action) {
         $paths = $this->_url_path->getRequestPaths();
         if (sizeof($paths) <= 1) {
             if ($paths[0] == '') {
                 $controller = 'index';
                 $action = 'index';
             } else {
                 if (substr($paths[0], 0, 1) == '~') {
                     $controller = 'index';
                     $action = 'index';
                 } else {
                     $controller = $paths[0];
                     $action = 'index';
                 }
             }
         } else {
             $start = 0;
             if (substr($paths[$start], 0, 1) == '~') {
                 $controller = 'index';
                 $action = 'index';
                 $method = substr($paths[$start], 1);
                 $start += 1;
             } elseif (substr($paths[$start + 1], 0, 1) == '~') {
                 $controller = $paths[$start];
                 $action = 'index';
                 $method = substr($paths[$start + 1], 1);
                 $start += 2;
             } elseif (isset($paths[$start + 2]) && substr($paths[$start + 2], 0, 1) == '~') {
                 $controller = $paths[$start];
                 $action = $paths[$start + 1];
                 $method = substr($paths[$start + 2], 1);
                 $start += 3;
             } else {
                 $controller = $paths[$start];
                 $action = $paths[$start + 1];
                 $start += 2;
             }
         }
     }
     $actionName = $controller . '_' . $action . '_Action';
     $action = CFactory::instance($actionName, array(), true, false);
     if (isset($method)) {
         $action->_method = $method;
     }
     $action->_actionName = $actionName;
     return $action;
 }