This version is outdated. You should upgrade your project to Mako 7.3 or Mako 8.1!

URL builder

The URL builder helps you build URLs for your Mako application.


The to method will return a Mako URL to the chosen path.

// Will print

$url = $urlBuilder->to('foo/bar');

// Will print

$url = $urlBuilder->to('foo/bar', ['key1' => 'value1', 'key2' => 'value2']);

The toRoute returns the URL of a named route.

$url = $urlBuilder->toRoute('home');

The base method will return the base URL of your application.

$url = $urlBuilder->base();

The current method will return the current URL of the main request.

$url = $urlBuilder->current();

The matches method returns true if the current URL path matches the pattern and false if not.

// Basic URL matching

$matching = $urlBuilder->matches('/news');

// Matching is done using regular expressions so you can also use character classes

$matching = $urlBuilder->matches('/news/article/([0-9]+)');