PHP Classes

Simple PHP Routers: Route HTTP requests to given callback functions

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
StarStarStarStar 66%Total: 57 All time: 10,566 This week: 96Up
Version License PHP version Categories
routers 1.0.0GNU General Publi...5HTTP, PHP 5, Design Patterns
Description 

Author

This package can route HTTP requests to given callback functions.

It can register several URL regular expression patterns and callback functions that will be called when the current request matches the respective pattern.

It can also take regular expressions to extract parameter values from the request URL.

Picture of Carlos Carvalho
  Performance   Level  
Name: Carlos Carvalho <contact>
Classes: 8 packages by
Country: Brazil Brazil
Innovation award
Innovation award
Nominee: 2x

Example

<?php


ini_set
('display_errors', 1);
require
"vendor/autoload.php";

$router = new App\Router\Router($_SERVER["REQUEST_URI"]);


$router->get('/',function(){
   echo
'home page';
});


$router->get('/posts','Blog#show');

$router->get('/posts/:id-:slug',function($id, $slug) use ($router){

    echo
$router->url('Blog#show',['id'=>1,'slug'=>'slugsd-idads']);

},
'posts.show')->with('id','[0-9]+')->with('slug','([a-z\-0-9]+)');

$router->get('/posts/:id','Blog#show');


$router->post('/posts/:id',function($id){

  
print_r($_POST);
});

$router->run();


Details

routers

Latest Stable Version Total Downloads Latest Unstable Version License

Simple Routers PHP

>Examples

<?php use App\Router\Router;

$router = new App\Router\Router($_SERVER["REQUEST_URI"]); $router->get('/',function(){

echo 'home page';

});

$router->get('/posts/:id-:slug',function($id, $slug) use ($router){

echo $router->url('Blog#show',['id'=>1,'slug'=>'slugsd-idads']);

},'posts.show')->with('id','[0-9]+')->with('slug','([a-z\-0-9]+)');

$router->get('/posts/:id','Blog#show');

$router->post('/posts/:id',function($id){

print_r($_POST); });

$router->run();

Use Custom Controllers

$router->get('/posts','Blog#show');

Create new Controller BlogController.php


  Files folder image Files (14)  
File Role Description
Files folder imagesrc (2 directories)
Files folder imagevendor (1 file, 1 directory)
Accessible without login Plain text file composer.json Data Auxiliary data
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file rewriterConfig.php Aux. Auxiliary script

  Files folder image Files (14)  /  src  
File Role Description
Files folder imageControllers (1 file)
Files folder imageRouter (3 files)

  Files folder image Files (14)  /  src  /  Controllers  
File Role Description
  Plain text file BlogController.php Class Class source

  Files folder image Files (14)  /  src  /  Router  
File Role Description
  Plain text file Route.php Class Class source
  Plain text file Router.php Class Class source
  Plain text file RouterException.php Class Class source

  Files folder image Files (14)  /  vendor  
File Role Description
Files folder imagecomposer (5 files)
  Accessible without login Plain text file autoload.php Aux. Auxiliary script

  Files folder image Files (14)  /  vendor  /  composer  
File Role Description
  Accessible without login Plain text file autoload_classmap.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_namespaces.php Aux. Auxiliary script
  Accessible without login Plain text file autoload_psr4.php Aux. Auxiliary script
  Plain text file autoload_real.php Class Class source
  Plain text file ClassLoader.php Class Class source

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 100%
Total:57
This week:0
All time:10,566
This week:96Up
 User Ratings  
 
 All time
Utility:83%StarStarStarStarStar
Consistency:83%StarStarStarStarStar
Documentation:83%StarStarStarStarStar
Examples:83%StarStarStarStarStar
Tests:-
Videos:-
Overall:66%StarStarStarStar
Rank:525