PHP Classes

Application PHP Router Class: Route requests with values from $_GET parameters

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

Author

This package can route requests with values from $_GET parameters.

It can check a given parameter passed to the current script using the request URL parameters and parses it.

The package can extract the controller's name and action from the parsed parameter so that the application can call the respective controller class.

Picture of SzpaQ
  Performance   Level  
Name: SzpaQ <contact>
Classes: 5 packages by
Country: Poland Poland
Age: ???
All time rank: 302571 in Poland Poland
Week rank: 106 Up5 in Poland Poland Up

Example

<?php

/**
 *
 * LICENCE
 * ALL RIGHTS RESERVED.
 * YOU ARE NOT ALLOWED TO COPY/EDIT/SHARE/WHATEVER.
 * IN CASE OF ANY PROBLEM CONTACT AUTHOR.
 * @author ?ukasz Szpak (szpaaaaq@gmail.com)
 * @Copyright 2018 SzpaQ
 * @license ALL RIGHTS RESERVED
 *
 * * */

include 'loader.php';
// These two was created for the testing purpose of App\Router class (same as UserController and autoloader)
require 'classes/Validate.php';
require
'classes/Controller.php';

// OPTIONAL set route string
// default value is _url
App\Router::setRoutingVariable('route');


// OPTIONAL set Validate class
App\Router::setValidator('Validate');

$_GET = array(
   
'route' => 'user/edit/45/SzpaaQ'
);

// create Router object
$router = new App\Router;
// let's get controller name
$controller = ucfirst($router->getControllerName()).'Controller';
// and action name
$action = $router->getActionName() .'Action';

// check if controller and action exists and call it in case of its true
if(class_exists($controller)) {
   
// We have created controller class for the testing purpose it will create router object or get it from array given in contructor
   
$controller = new $controller(array('router' => $router));
    if(
method_exists($controller, $action)) {
       
$controller->$action(); // check Controllers/UserController.php
   
}
   
// in case of there was not found such method you can redirect it for example to error page
   
}




  Files folder image Files  
File Role Description
Files folder imageclasses (1 directory)
Files folder imageexample (3 files, 2 directories)
Accessible without login Plain text file README.md Doc. Documentation

  Files folder image Files  /  classes  
File Role Description
Files folder imageApp (1 file)

  Files folder image Files  /  classes  /  App  
File Role Description
  Plain text file Router.php Class Class source

  Files folder image Files  /  example  
File Role Description
Files folder imageclasses (2 files)
Files folder imageControllers (1 file)
  Accessible without login Plain text file .htaccess Data Auxiliary data
  Accessible without login Plain text file index.php Example Example script
  Accessible without login Plain text file loader.php Example Example script

  Files folder image Files  /  example  /  classes  
File Role Description
  Plain text file Controller.php Class Class source
  Plain text file Validate.php Class Class source

  Files folder image Files  /  example  /  Controllers  
File Role Description
  Plain text file UserController.php Class Class source

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