コード例 #1
0
 /**
  * TODO
  * 
  * @param string $uri
  * @return string
  */
 public function dispatch($uri = null)
 {
     $router = $this->getRouter();
     $request = new EhrlichAndreas_Mvc_Request($uri);
     $this->setBaseUrl($request->getBaseUrl());
     $request = $router->route($request);
     $this->setRequest($request);
     $response = $this->runByParameter($request);
     $this->getView()->assign('maincontent', $response);
     $layout = $this->getView()->getLayout();
     return $this->getView()->render($layout, true);
 }
コード例 #2
0
 /**
  * Find a matching route to the current PATH_INFO and inject
  * returning values to the Request object.
  *
  * @throws EhrlichAndreas_Mvc_Exception
  * @return EhrlichAndreas_Mvc_Request Request object
  */
 public function route($request)
 {
     if ($this->_useDefaultRoutes) {
         $this->addDefaultRoutes();
     }
     if (!is_object($request)) {
         $request = new EhrlichAndreas_Mvc_Request($request);
     }
     // Find the matching route
     $routeMatched = false;
     $match = $request->getPathInfo();
     foreach (array_reverse($this->_routes, true) as $name => $route) {
         if ($params = $route->match($match)) {
             $this->_setRequestParams($request, $params);
             $this->_currentRoute = $name;
             $routeMatched = true;
             break;
         }
     }
     if (!$routeMatched) {
         throw new EhrlichAndreas_Mvc_Exception('No route matched the request', 404);
     }
     if ($this->_useCurrentParamsAsGlobal) {
         $params = $request->getParams();
         foreach ($params as $param => $value) {
             $this->setGlobalParam($param, $value);
         }
     }
     return $request;
 }