Download the PHP package artkoder/peasy-router without Composer
On this page you can find all versions of the php package artkoder/peasy-router. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download artkoder/peasy-router
More information about artkoder/peasy-router
Files in artkoder/peasy-router
Package peasy-router
Short Description A simple, easy to use, and opinionated router for PHP
License MIT
Homepage https://github.com/musciencia/peasy.git
Informations about the package peasy-router
Peasy Router
Peasy Router is an easy peasy and opinionated router for PHP. It is meant to be used with small projects that need a very basic ruting functionality. Nothing complicated.
Installation
Using composer
Configure your .htaccess file
Add the following code to your .htaccess
inside a public folder
at the same level as your index.php
.
Setting index.php
Routes
You can define your routes inside a directory. You can use either a text file with extension .routes
or a normal
.php
file. Peasy router will scan all the route files inside the directory recursivelly. You can use either of
the file formats or combine both if you so desire.
Defining your routes using a .routes
file
Here is a sample web.routes
file:
Defining your routes using a .php
file
The previous routes can alternatively be defined in a .php
file as follows:
Controllers
Once you have your route definitions, you can create the controllers for your paths.
Here is an example using the previous route definitions:
Query parameters
Peasy router maps all query parameters as arguments to the controllers function.
So, if you request the following path: https://peasy.test/budget/2023-09-01/2023-12-31?var=value
,
the controller will expect to get a variable $var
, so you need to declare it.
To avoid errors when a query parameter is not present, you can make variables optional.
Here is an example: