Skip to content

A simple & lightweight PHP Router made with Object Oriented PHP.

License

Notifications You must be signed in to change notification settings

chahal26/php-simple-router

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

37 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chahal26/php-simple-router

A simple & lightweight PHP Router made with Object Oriented PHP. Built with ❤️ by Sahil Chahal

It currently supports static routes only.

Prerequisites/Requirements

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>";
    });

About

A simple & lightweight PHP Router made with Object Oriented PHP.

Topics

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Sponsor this project

Packages

No packages published

Languages