PHP Classes

PHP Router Class: Call a function when the request matches a pattern

Recommend this page to a friend!
  Info   View files Documentation   View files View files (3)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not yet rated by the usersTotal: 71 This week: 1All time: 10,230 This week: 560Up
Version License PHP version Categories
php-route 1.0The PHP License5HTTP, PHP 5, Design Patterns
Description 

Author

This class can call a function when the request matches a pattern.

It can register regular expressions to match the current HTTP request URI.

The class can associate each regular expression to a given callback function.

It can also check if any of the registered regular expressions. The first regular expression that matches the URL of the current HTTP request will make the class call the associated callback function.

Picture of Mauro Junior
  Performance   Level  
Name: Mauro Junior <contact>
Classes: 2 packages by
Country: Brazil Brazil
Age: 31
All time rank: 4435359 in Brazil Brazil
Week rank: 416 Up36 in Brazil Brazil Up

Documentation

PHP-route

A PHP Route Class

How to use ?

To use PHP Router Class you need to clone our repository. Considering you've already made it, make a file .php as you preferer.

This example doesn't use PSR4/0 however we are using namespace, i recommend you to keep it.

Put the code below in your file .php

use \Src\Core\Router;

Router::route('/', function(){	
  echo "You're in home page";
});
Router::execute($_SERVER['REQUEST_URI']);

To every created router you need re-execute the router as you seen above. The next example show how you can use regex pattern.

use \Src\Core\Router;

Router::route("/(\w+)/", function($id){	
  echo 'My id is: {$id}';
});
Router::execute($_SERVER['REQUEST_URI']);

  Files folder image Files  
File Role Description
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Plain text file Router.class.php Class Class source

 Version Control Unique User Downloads Download Rankings  
 100%
Total:71
This week:1
All time:10,230
This week:560Up