Download the PHP package lablnet/zestrouter without Composer
On this page you can find all versions of the php package lablnet/zestrouter. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package zestrouter
ZestRouter
ZestRouter is a small but powerful routing class for php
Features
- Can be used with all HTTP Methods
- Flexible regular expression routing
- Custom regexes
- Router with controllers by namespaces
- Routers using closure
install
Run the command in terminal/cmd
Getting started
Requirements
- PHP 7 or newest
- Composer
Rewrite all requests
Apache (.htaccess)
Nginx (nginx.conf)
Adding Routes
By now, you should have rewrite all requests
simple (default way)
there are many to two ways to add the routes
Using add method
The add()
method accepts the following parameters.
$route
(string)
This is the route pattern to match against. This can be a plain string, a custom regex.
$params
(array|string|Closure)
This is paramter for controllers and controller method or closure
(array) => ['controller' => 'Home', 'action' => 'index']
(string) => "Home@index"
(closure) => function () { echo "Welcome"; }
$method
(string)
This is a pipe-delimited string of the accepted HTTP requests methods.
Example: GET|POST|PATCH|PUT|DELETE
Using rests method
there are 5 request methods supports `get(),post(),put(),patch(),delete()``
These methods accepts the following parameters.
$route
(string)
This is the route pattern to match against. This can be a plain string, a custom regex.
$params
(array|string|Closure)
This is paramter for controllers and controller method or closure
(array) => ['controller' => 'Home', 'action' => 'index']
(string) => "Home@index"
(closure) => function () { echo "Welcome"; }
Example adding the routes
For quickly adding multiple routes, you can use the addRoutes method. This method accepts an array or any kind of traversable.
Matching Requests
To match the current request, just call the customDispatch()
method without any parameters.
If a match was found, the customDispatch()
method will return an associative array
Processing Requests
ZestRouter process requests for you but so you are free to use the method you prefer. To help you get started, here's a simplified example using closures.