示例#1
0
文件: Request.php 项目: navtis/xerxes
 /**
  * Set the router from the MVC framework
  * 
  * This will push the route paths into the request as parameters
  * 
  * @param RouteStack $router
  */
 public function setRouter(RouteStack $router)
 {
     $this->router = $router;
     // now extract the route elements and set them as params
     $route_match = $router->match($this);
     if ($route_match instanceof RouteMatch) {
         foreach ($route_match->getParams() as $name => $value) {
             $this->setParam($name, $value);
         }
     }
 }
示例#2
0
文件: Url.php 项目: rafalwrzeszcz/zf2
 /**
  * Generates an url given the name of a route.
  *
  * @see    Zend\Mvc\Router\Route::assemble()
  * @param  string  $name               Name of the route
  * @param  array   $params             Parameters for the link
  * @param  array   $options            Options for the route
  * @param  boolean $reuseMatchedParams Whether to reuse matched parameters
  * @return string Url                  For the link href attribute
  * @throws Exception\RuntimeException  If no RouteStack was provided
  * @throws Exception\RuntimeException  If no RouteMatch was provided
  * @throws Exception\RuntimeException  If RouteMatch didn't contain a matched route name
  */
 public function __invoke($name = null, array $params = array(), array $options = array(), $reuseMatchedParams = false)
 {
     if (null === $this->router) {
         throw new Exception\RuntimeException('No RouteStack instance provided');
     }
     if ($name === null) {
         if ($this->routeMatch === null) {
             throw new Exception\RuntimeException('No RouteMatch instance provided');
         }
         $name = $this->routeMatch->getMatchedRouteName();
         if ($name === null) {
             throw new Exception\RuntimeException('RouteMatch does not contain a matched route name');
         }
     }
     if ($reuseMatchedParams && $this->routeMatch !== null) {
         $params = array_merge($this->routeMatch->getParams(), $params);
     }
     $options['name'] = $name;
     return $this->router->assemble($params, $options);
 }