Drupal 8 - retrieving URI of current request

If you're used to relying on $_GET['q'] from Drupal 7 (& earlier), you might be in for a surprise with Drupal 8, as $_GET['q'] is no longer defined for any request. Instead, Drupal 8 ships with a series of helper functions:

current_path() - returns the internal Drupal path (ex. node/123)

request_path() - returns the alias (ex. blog/my-post)

base_path() - returns the base path for your Drupal site (ex. /mysite/, if your site is accessible at foo.com/mysite)

request_uri() - returns the full URI, including base path, alias, and any query arguments (ex. /mysite/blog/my-post?foo=bar)

comments powered by Disqus