Download the PHP package dlpwd/router without Composer
On this page you can find all versions of the php package dlpwd/router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Package router
Short Description Lightweight router library with named url parameters
License MIT
Homepage https://github.com/DaveLegg/dlpwd-router
Informations about the package router
dlpwd-router
Lightweight router library with named url parameters
Basic Usage
Configuring Routes
The router supports three request methods, GET, POST and DELETE. There are corresponding methods in the router class to add routes for each request method
$_method
The request method can be specified when using the addRoute method on the router to create a new route. This method is useful when adding routes in bulk, for example after loading from a database or file, rather than using hard-coded routes.
$_url
The URL for the route should be specified with a leading forward-slash. Trailing forward-slashes are optional. The router will match requests with and without a trailing forward-slash to the same route. Parameters are specified within curly-braces. The name of the parameters must match the name of the parameters on the handler function, otherwise they will not be passed through
$_handler
The handler argument specifies the function to call if the route matches. The function can be specified in as any valid PHP callable
Resolving Routes
To have the router examine a URL and call the relevant controller, execute the resolve method. The resolve method will return any value returned by the controller function
$_url
Omitting or passing null to the $_url parameter will cause the router to use the value of $_SERVER['REQUEST_URI']. Pass a url to this argument to manually run the router for a different URL than the one being requested
$_method
Omitting or passing null to the $_method parameter will cause the router to use the value of $_SERVER['REQUEST_METHOD']. Pass a method to this argument to override that value. Most useful when manually running the router with a different URL as above