PHP Router is a simply and usefull php router created by monarch studio and hosted on .creative.
Manage easily your routes and catch errors in one class.
PHP Router uses composer to autoload class.
Download composer here and check documentation. After installation, run composer :
php composer-setup.php --install-dir=bin --filename=composer
php composer.pharAll routes are defined in index.php. You can call POST, GET, PUT or DELETE HTTP verb. You can add most in Router.php if you want.
Here call a controller with 'CONTROLLER#METHOD' schema.
$router->get('/', 'Example#show');Some example with other verbs and callable directly in function.
$router->post('/route-to-post', function(){ echo "Something to show"; });
$router->put('/route-to-put', function(){ echo "Something to show"; });
$router->delete('/route-to-delete', function(){ echo "Something to show"; });You can passed dynamic values in routes with :key schema.
Here call a controller with 'CONTROLLER#METHO' schema and retrieve the id in $id parameter.
$router->get('/article/:id', 'Example#show');You can add multiple variables in one route
$router->get('/article/:id/:slug', function($id, $slug){ echo "My article " . $slug; });
$router->put('/article/:userId/:id', function($userId, $id){ echo "Article updated !"; });PHP Router include Twig if you want to use it. If you don't know what it is, visit the website.
This is exactly the same callables.
Pull requests are welcome. For major changes, please open an issue first to discuss what you would like to change.
Please make sure to update tests as appropriate.
Free for all.