simplydi / simplyrouter
A simple PHP routing system for small apps
Installs: 1
Dependents: 0
Suggesters: 0
Security: 0
Stars: 2
Watchers: 1
Forks: 0
Open Issues: 0
pkg:composer/simplydi/simplyrouter
This package is auto-updated.
Last update: 2025-10-04 17:55:54 UTC
README
A simple routing system in PHP
Notes
- built for learning purpose
- it is a very simple router. For more powerful features like route naming and middleware implementations, go for League Route or Symfony router
- suitable only for small projects
Usage
include 'src/Router.php'; // or use composer: require 'vendor/autoload.php' $route = new \SimplyDi\SimplyRouter\Router(); $route->match('/', function () { echo "Welcome us"; }); $route->match('/about', function () { echo "About us"; }); $route->match('/policy/privacy', function () { echo "PRIVACY us"; }); $route->match('/post/{slug}', function ($params) { $slug = $params['slug']; echo "Post with slug: " . $slug; }); # using controller classes $route->match('/{slug}', function ($params) { $slug = $params['slug']; return (new PageController)->single($slug); }); $route->run(); // run the router