chahal26 / php-simple-router
Simple Routing made with OOPS in PHP
Fund package maintenance!
chahal26
Requires
- php: >=8.0.0
This package is auto-updated.
Last update: 2025-06-17 19:07:00 UTC
README
A simple & lightweight PHP Router made with Object Oriented PHP. Built with ❤️ by Sahil Chahal
It currently supports static routes only.
Prerequisites/Requirements
- PHP >= 8.0
- URL Rewriting
Installation
chahal26/php-simple-router
can be easily installed using
composer require chahal26/php-simple-router
Usage
Create an instance of \Chahal26\PhpSimpleRouter\Router
, define some routes, and run it.
require_once 'vendor/autoload.php'; use Chahal26\PhpSimpleRouter\Router; /* Creating Route Instance */ $router = new Router(); /* Defining Routes */ /* Execute Routes */ $router->run();
Available Routing Methods
- GET
- POST
Defining Routes
Static Routes
$router->get('route', function() { /* ... */ }); $router->post('route', function() { /* ... */ });
With Controller
$router->get('/about', '\App\Controllers\PagesController@about');
Or a namespace can also be defined
$router->setNamespace('\App\Controllers'); $router->get('/about', 'PagesController@about');
Example
$router->get('/', function(){ echo "<h1>Welcome To Home Page</h1>"; }); $router->get('/contact', function(){ echo "<h1>Welcome To Contact Page</h1>"; });