PHP Classes

Simple PHP Router Library: Route requests to different scripts based on URLs

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 79%Total: 584 All time: 5,297 This week: 43Up
Version License PHP version Categories
folderbase-php-route 0.13GNU General Publi...5HTTP, PHP 5, Files and Folders, Desig...
Description 

Author

This class can route requests to different scripts based on URLs.

It takes an array of supported routes and checks it to see if the current request URL matches any of the routes.

The class can route the requests to the respective script defined in the routes array.

Missing routes makes the class handle the request with a not found script.

Picture of afshin akhgar
  Performance   Level  
Name: afshin akhgar <contact>
Classes: 3 packages by
Country: Iran Iran
Age: 39
All time rank: 251042 in Iran Iran
Week rank: 170 Up2 in Iran Iran Up
Innovation award
Innovation award
Nominee: 1x

Recommendations

url rewriting
I need rewrite url in my site

Example

<?php
/**
 * Created by PhpStorm.
 * User: akhgar-af
 * Date: 8/9/2016
 * Time: 10:46 AM
 */

GLOBAL $includePath;
GLOBAL
$assetsUrl;
$includePath = '/';
               
require_once
'./lib/router.php';
$router = new Router();
return
$router->go(array(
   
'afshin'=>'examples/afshin.php',
   
'/'=>'examples/afshin.php',
   
'test'=> 'examples/test.php',
   
'sub/iran' => 'examples/sub/iran.php',
   
'sub/subsub/module' => 'examples/sub/subsub/module/module.php',
   
'sub/subsub/param/:param1/:param2/:param3' => 'examples/sub/subsub/module/param.php',
));


Details

Folderbase PHP Router!

[AUR]()

A lightweight and simple object oriented PHP Router. Built by Afshin Akhgar- http://www.akhgar.net

Features

  • Static Route
  • Dynamic Route
  • Parameter Support => akhgar.net/param1/a/param2/b
  • Folder and file and subfolders routing
  • Subrouting
  • Parameter sending over url and query String Support
  • Custom 404 handling
  • Works fine in subfolders > Note: > - This Library is under development

<i class="icon-file"></i> Demo

  • First of all get the lib
  • Include it in your php index file
  • Call The router go Method
GLOBAL $includePath;
GLOBAL $assetsUrl;
$includePath = '/';
				
require_once './lib/router.php';
$router = new Router();
return $router->go(array(
	'afshin'=>'examples/afshin.php',
	'/'=>'examples/afshin.php',
	'/sub/:param1/:param2/:param3:/param:4'=>'examples/params.php',
));

<i class="icon-file"></i> Parameter

'/sub/:param1/:param2/:param3:/param:4'=>'examples/params.php'

get Parameters with Array ($parameters)

  Files folder image Files (12)  
File Role Description
Files folder imageexamples (2 files, 1 directory)
Files folder imagelib (1 file)
Accessible without login Plain text file .htaccess Data Auxiliary data
Accessible without login Plain text file 404.php Aux. Auxiliary script
Accessible without login Plain text file index.php Example Example script
Accessible without login Plain text file LICENSE Lic. License text
Accessible without login Plain text file README.md Doc. Documentation
Accessible without login Plain text file _config.yml Data Auxiliary data

  Files folder image Files (12)  /  examples  
File Role Description
Files folder imagesub (1 file, 1 directory)
  Accessible without login Plain text file afshin.php Aux. Auxiliary script
  Accessible without login Plain text file test.php Aux. Auxiliary script

  Files folder image Files (12)  /  examples  /  sub  
File Role Description
Files folder imagesubsub (1 directory)
  Accessible without login Plain text file iran.php Aux. Auxiliary script

  Files folder image Files (12)  /  examples  /  sub  /  subsub  
File Role Description
Files folder imagemodule (2 files)

  Files folder image Files (12)  /  examples  /  sub  /  subsub  /  module  
File Role Description
  Accessible without login Plain text file module.php Aux. Auxiliary script
  Accessible without login Plain text file param.php Aux. Auxiliary script

  Files folder image Files (12)  /  lib  
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  
 100%
Total:584
This week:0
All time:5,297
This week:43Up
 User Ratings  
 
 All time
Utility:100%StarStarStarStarStarStar
Consistency:100%StarStarStarStarStarStar
Documentation:91%StarStarStarStarStar
Examples:100%StarStarStarStarStarStar
Tests:-
Videos:-
Overall:79%StarStarStarStar
Rank:32