The Router service is designed for interacting with route data in the HLEB2 framework.
Ways to use Router in controllers (and all classes inherited from Hleb\Base\Container) demonstrated with relative URL formation by route name:
Example of accessing Router in application code:
The Router object can also be obtained via dependency injection using the Hleb\Reference\Interface\Router interface.
For simplicity, further examples will only include references through Hleb\Static\Router.
The url() method is intended for converting a route name into a relative URL address. A simple example:
Since route addresses may have dynamic parameters and an optional trailing part, specify these in additional arguments when present.
The address() method is similar to the url() method but returns the full URL including the HTTP scheme and domain name from the current request. Since the domain is assigned only the current one, use concatenation with Route::url() for another domain.
The returned address for the specified methods will include or exclude a trailing slash based on the corresponding framework settings.
Built-in framework functions url() and address() are shorthand for calling the same-named Router methods.
The name() method can be used to find out the name of the current route, if it is assigned.
The data() method returns data for the current middleware if it has been set in the route. It can be used only in middleware.
← Redirect Settings →