URL
The URL utility provides a collection of helper functions to assist developers in building routes and performing redirects.
Route
Returns the current request's route. From the url https://domain.com/route/to/page?q=search+query
, returns /route/to/page
Parse QueryString
Returns the query string of the current request. From the url https://domain.com/route/to/page?q=search+query
returns ?q=search+query
.
File Type
Returns the file extension from a URL or null if not extension is found.
URI
Returns the decoded URI of the current request.
Route Parts
Explodes the a request's route by '/' and returns the resulting parts.
Host
Returns the current request's host.
Protocol
Returns the current request's protocol. Expected return values are http://
or https://
.
HTTP Method
Returns the HTTP method used in the current request. Valid return values include get
, post
, put
, patch
, delete
.
Make URL From Route
A route should only be hard-coded in once place: the module config. From there, it should never be directly referenced again. The make()
method is used to build URLs by referencing the name of the route, instead of the route's actual path. This allows developers to change routes without breaking links throughout the application.
Consider the following route definitions:
The members_users_list
route doesn't have any dynamic parameters. The members_account
route has 1 dynamic parameter (a user Id).
The
url::make()
method's first parameter is the name of the route. The number of subsequent parameters will always match the number of dynamic parameters in the route.e.g To build a route with 4 dynamic parameters,
the make()
method will require 4 additional parameters after the route name.
Redirect
To force a page redirect in any part of the application, use the redirect()
method.
This method is meant for redirecting to third-party URLs. To redirect to an application route, use
redirectId()
.
Redirect to Route
Redirects to a named route in the application.
isCurrentRoute
Compares the route of the current request's with a given route.
Find route by ID
See the routing documentation.
Last updated