PHP Classes

How to Implement a PHP Router Script using the Router App: Route HTTP requests to given PHP scripts

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
Not enough user ratingsTotal: 134 All time: 9,301 This week: 46Up
Version License PHP version Categories
router_app 1.0.2Free for non-comm...5HTTP, PHP 5, Design Patterns
Description 

Author

This package can route HTTP requests to given PHP scripts.

It can register multiple URL patterns and an HTTP request method (GET or POST) that an application is accepting requests.

The package can load a PHP script to execute when it processes a HTTP request when the request URL matches one of the registered URL patterns.

If the current HTTP request does not match any of the registered URL patterns, the package can load and execute a script to handle HTTP status code 404 if that script exists.

Picture of Aladdin
Name: Aladdin <contact>
Classes: 1 package by
Country: Egypt Egypt
Age: 54
All time rank: 431949 in Egypt Egypt
Week rank: 216 Up3 in Egypt Egypt Up

Example

<?php

// This is a simple and powerful Router App like frameworks
// first build your page as you want and need inside components directory .. like home.php or login.php or any you want
// i just biuld home.php, about.php and contact.php for example
// then make a new instance for Router Class
// then use get($route, $pathToFile); for get method
// or use post($route, $pathToFile); for post method
// then run();
// as like bellow

// note: any route doesn't installed as like bellow .. it will response and render a 404 not found page

include_once('./Router/Router.php');

$pages = new Router();
$pages->get('/', './components/home.php');
$pages->get('/about', './components/about.php');
$pages->get('/contact', './components/contact.php');

$pages->run();


Details

routerApp

  • This is a simple and powerful Router App like frameworks
  • first build your page as you want and need inside components directory .. like home.php or login.php or any you want
  • I just biuld home.php, about.php and contact.php for example
  • then make a new instance for Router Class
  • then use get($route, $pathToFile); for get method
  • or use post($route, $pathToFile); for post method
  • then run();
  • as like in index.php
  • note: any route doesn't installed as like in index.php .. it will response and render a 404 not found page

  Files folder image Files (9)  
File Role Description
Files folder imagecomponents (5 files)
Files folder imageRouter (1 file)
Plain text file .htaccess Aux. useful magic server tool
Plain text file index.php Example Example script
Plain text file README.md Doc. Documentation

  Files folder image Files (9)  /  components  
File Role Description
  Plain text file about.php Aux. Auxiliary script
  Plain text file contact.php Aux. Auxiliary script
  Plain text file home.php Aux. Auxiliary script
  Plain text file index.php Aux. Auxiliary script
  Plain text file _404.php Aux. Auxiliary script

  Files folder image Files (9)  /  Router  
File Role Description
  Plain text file Router.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  
 88%
Total:134
This week:0
All time:9,301
This week:46Up
User Comments (2)
Very well done!
1 year ago (Roberto del Pino)
80%StarStarStarStarStar
very easy and good work
2 years ago (Aladdin Masoud)
80%StarStarStarStarStar