PHP Classes

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

Recommend this page to a friend!

  Author Author  
Picture of Mauro Junior
Name: Mauro Junior <contact>
Classes: 2 packages by
Country: Brazil Brazil


  Detailed description   Download Download .zip .tar.gz  
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.

Details

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']);

  Classes of Mauro Junior  >  PHP Router Class  >  Download Download .zip .tar.gz  >  Support forum Support forum  >  Blog Blog  >  RSS 1.0 feed RSS 2.0 feed Latest changes  
Name: PHP Router Class
Base name: php-route
Description: Call a function when the request matches a pattern
Version: -
PHP version: 5
License: The PHP License
 
  Groups   Applications   Files Files  

  Groups  
Group folder image HTTP HTTP protocol clients, headers and cookies View top rated classes
Group folder image PHP 5 Classes using PHP 5 specific features View top rated classes
Group folder image Design Patterns Implementations of well known design patterns View top rated classes


  Applications that use this package  
No pages of applications that use this class were specified.

Add link image If you know an application of this package, send a message to the author to add a link here.

  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

Download Download all files: php-route.tar.gz php-route.zip
NOTICE: if you are using a download manager program like 'GetRight', please Login before trying to download this archive.
For more information send a message to info at phpclasses dot org.