Download the PHP package flatpixels/light-route without Composer
On this page you can find all versions of the php package flatpixels/light-route. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download flatpixels/light-route
More information about flatpixels/light-route
Files in flatpixels/light-route
Package light-route
Short Description A simple php router easy to setup and use.
License MIT
Informations about the package light-route
Light-Route - A simple php router easy to setup and use
This library provides a simple router configuration and its routes.
Install
Usage
First of all, you have to setup your routes by doing so:
-
Get an instance of the Router:
- Register your routes into the router:
Now that you have configured your routes, you have to resolve the current user request URI by calling the resolver:
Register routes into the router
Use the method addRoute(string $requestMethod, $string requestUrl, callable $callable, [, string $routeName ])
to add routes into the router. The method takes 4 arguments:
$requestMethod
: Set the user request method. only support: GET, POST.$requestUrl
: Set the request url that will resolve the route.$callable
: A callback that define the action to execute when the route is reached.$routeName
: (Optional) set the name of the route.
Register routes with params
You can register routes by passing datas into its url by using the notation :paramName
. Example:
In the code below, i setup a route by passing the id
into its url.
You can pass as much as data you want:
Routes with params validator
By passing parameters into the route url, you can use the format(array $paramsValidators)
method to set a validation constraint:
The format(...)
method takes a pair $key => $value
array where $key
is a parmater name, and $value
a regex that represents the valid values for this parameter.
Redirect to a specific route
You can use the router by calling the redirect(..)
method, to redirect you to another route. The method takes 2 arguments:
$routeName
: The name of the route to which we must be redirected.$params
: (Optional) An array of$key => $value
where$key
is a parmater name, and$value
the value of the paramter: