W3cubDocs

/Drupal 8

public static function Drupal::url

public static Drupal::url($route_name, $route_parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE)

Generates a URL string for a specific route based on the given parameters.

This method is a convenience wrapper for generating URL strings for URLs that have Drupal routes (that is, most pages generated by Drupal) using the \Drupal\Core\Url object. See \Drupal\Core\Url::fromRoute() for detailed documentation. For non-routed local URIs relative to the base path (like robots.txt) use Url::fromUri()->toString() with the base: scheme.

Parameters

string $route_name: The name of the route.

array $route_parameters: (optional) An associative array of parameter names and values.

array $options: (optional) An associative array of additional options.

bool $collect_bubbleable_metadata: (optional) Defaults to FALSE. When TRUE, both the generated URL and its associated bubbleable metadata are returned.

Return value

string|\Drupal\Core\GeneratedUrl A string containing a URL to the given path. When $collect_bubbleable_metadata is TRUE, a GeneratedUrl object is returned, containing the generated URL plus bubbleable metadata.

Deprecated

as of Drupal 8.0.x, will be removed before Drupal 9.0.0. Instead create a \Drupal\Core\Url object directly, for example using Url::fromRoute().

See also

\Drupal\Core\Routing\UrlGeneratorInterface::generateFromRoute()

\Drupal\Core\Url

\Drupal\Core\Url::fromRoute()

\Drupal\Core\Url::fromUri()

File

core/lib/Drupal.php, line 542
Contains \Drupal.

Class

Drupal
Static Service Container wrapper.

Code

public static function url($route_name, $route_parameters = array(), $options = array(), $collect_bubbleable_metadata = FALSE) {
  return static::getContainer()->get('url_generator')->generateFromRoute($route_name, $route_parameters, $options, $collect_bubbleable_metadata);
}

© 2001–2016 by the original authors
Licensed under the GNU General Public License, version 2 and later.
Drupal is a registered trademark of Dries Buytaert.
https://api.drupal.org/api/drupal/core!lib!Drupal.php/function/Drupal::url/8.1.x