Skip to content

bharatkumar200/SimplyRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SimplyRouter

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

About

A simple routing system in PHP

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages