Ergo\Routing\Router::buildUrl PHP Method

buildUrl() public method

Build a URL path based on a route name and associated parameters.
public buildUrl ( string $name, array $parameters = [], $baseUrl = null )
$name string
$parameters array
    public function buildUrl($name, $parameters = array(), $baseUrl = null)
    {
        $url = $this->routeByName($name)->interpolate($parameters);
        if ($baseUrl) {
            return (string) $baseUrl->relative($url);
        } else {
            if (isset($this->_baseUrl)) {
                return $this->_baseUrl->relative($url);
            } else {
                return $url;
            }
        }
    }

Usage Example

Example #1
0
 public function testInterpolationFailsWithStarRoutes()
 {
     $router = new Routing\Router();
     $router->connect('/{fruit}/*', 'fruit');
     $this->setExpectedException('Ergo\\Routing\\Exception');
     $router->buildUrl('fruit', array('fruit' => 'apple'));
 }