Url Generator
Tomahawk's Url Generator extends Symfonys Url Generator, allowing you to generate a url to a
route
or path
given.
The easiest way to use the Url Generator component is to make sure your Controllers extend
Tomahawk\Routing\Controller
. You then have access to it through $this->url
.
Otherwise just add the following parameter to the construct method of your
Controller Tomahawk\Url\UrlGeneratorInterface
and it will get injected in through the Service Container.
Generating URL's
You can generate URL's to various paths, such as a route, path, secure path and even an asset such as JS, CSS or an image.
Generate A URL To A Route
You can generate a URL to a route doing the following:
Generate A URL To A Route With Parameters
Say you have a route defined in the following way, that requires parameters:
You can generate a URL to that route by doing the following:
Generate A URL To A Non Secure Path
You can generate a URL by doing the following:
Generate A URL To A Secure Path
You can generate a URL by doing the following:
Generate A URL To A Path With Extra Parameters
You can generate a URL by doing the following: