Skip to content

A simple PHP Router created in a single file differentiating verbs from requisition and simulating requests for debug

Notifications You must be signed in to change notification settings

rbgadotti/SimpleRouter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 

Repository files navigation

Simple Router

An simple PHP Router created in a single file differentiating verbs from requisition, simulating requests and work with url params

What I Learned

  • How a router works
  • How to use regex to detected url params

Usage

Create an index.php file with the following contents:

<?php

require_once('SimpleRouter.php');

$router = new SimpleRouter();

// $router->setSimulatedRequest('POST', '/users/10/posts/rafael', 'page=1');

$router->any('/user/:id', function($id){
    echo '<h1>User id: '. $id . '</h1>';
});

$router->get('/hello', function(){
    echo '<h1>Hello World!</h1>';
});

$router->get('/profile/:id', 'ProfileController@showProfile');

$router->run();

About

A simple PHP Router created in a single file differentiating verbs from requisition and simulating requests for debug

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages