A simple & lightweight PHP Router made with Object Oriented PHP. Built with ❤️ by Sahil Chahal
It currently supports static routes only.
- PHP >= 8.0
- URL Rewriting
chahal26/php-simple-router
can be easily installed using
composer require chahal26/php-simple-router
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();
- GET
- POST
$router->get('route', function() { /* ... */ });
$router->post('route', function() { /* ... */ });
$router->get('/about', '\App\Controllers\PagesController@about');
Or a namespace can also be defined
$router->setNamespace('\App\Controllers');
$router->get('/about', 'PagesController@about');
$router->get('/', function(){
echo "<h1>Welcome To Home Page</h1>";
});
$router->get('/contact', function(){
echo "<h1>Welcome To Contact Page</h1>";
});