This version is outdated. You should upgrade your project to Mako 12.1!
Learn more

URL builder



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


Usage

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

// Will print http://example.org/foo/bar

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

// Will print http://example.org/foo/bar?key=value&key2=value2

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

The phptoRoute returns the URL of a named route.

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

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

$url = $urlBuilder->base();

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

$url = $urlBuilder->current();

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

// Basic URL matching

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

// You can also use regular expressions

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