Skip to content

6d. Generating URLs

Gjero Krsteski edited this page Dec 2, 2014 · 4 revisions

Retrieving the application's base URL:

  $url = URL::base();

Generating a URL relative to the base URL:

$url = URL::to('user/show');

Generating a HTTPS URL:

$url = URL::asHttps('user/login');

Retrieving the current URL:

$url = URL::current();

Retrieving the current URL including query string:

$url = URL::full();

##URLs To Routes

Generating a URL to a named route:

$url = URL::toRoute('user/show');

Sometimes you may need to generate a URL to a named route, but also need to specify the values that should be used instead of the route's URI wildcards. It's easy to replace the wildcards with proper values:

Generating a URL to a named route with wildcard values:

$url = URL::compute('user/profile', array($username));

##URLs To Controller Actions

Generating a URL to a controller action:

$url = URL::compute('user/show');

Generating a URL to an action with wildcard values:

$url = URL::compute('user/show', array($username));

##URLs To Assets

Generating a URL to an asset:

$url = URL::toAsset('js/jquery.js');

##URL Helpers

There are several global functions for generating URLs designed to make your life easier and your code cleaner:

Generating a URL relative to the base URL:

$url = Pimf\url('user/show');