Пример #1
0
 /**
  * dispatch URI
  *
  * @param string $uri in format "module/controllers"
  * @param array $params of request
  * @param string $method HTTP
  * @param bool $ajax
  * @return void
  */
 protected function dispatchUri($uri, array $params = null, $method = Http\Request::METHOD_GET, $ajax = false)
 {
     $this->prepareRequest($uri, $params, $method, $ajax);
     $uri = trim($uri, '/ ');
     list($module, $controller) = explode('/', $uri);
     // set default controllers
     if (!$controller) {
         $controller = Request::getController();
     }
     Request::setModule($module);
     Request::setController($controller);
     Request::setRequestUri($uri);
     $this->getApp()->process();
 }
Пример #2
0
 /**
  * Process router by default rules
  *
  * Default routers examples
  *     /
  *     /:module/
  *     /:module/:controller/
  *     /:module/:controller/:key1/:value1/:key2/:value2...
  *
  * @return bool
  */
 protected function processRoute()
 {
     $uri = Request::getCleanUri();
     $uri = trim($uri, '/');
     $params = explode('/', $uri);
     if (sizeof($params)) {
         Request::setModule(array_shift($params));
     }
     if (sizeof($params)) {
         Request::setController(array_shift($params));
     }
     if ($size = sizeof($params)) {
         // save raw params
         Request::setRawParams($params);
         // remove tail
         if ($size % 2 == 1) {
             array_pop($params);
             $size = sizeof($params);
         }
         // or use array_chunk and run another loop?
         for ($i = 0; $i < $size; $i = $i + 2) {
             Request::setParam($params[$i], $params[$i + 1]);
         }
     }
     return true;
 }