PHP Classes

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

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 yet rated by the usersTotal: 86 All time: 10,018 This week: 74Up
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: 300570 in Poland Poland
Week rank: 216 Up4 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 (8)  
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 (8)  /  classes  
File Role Description
Files folder imageApp (1 file)

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

  Files folder image Files (8)  /  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 (8)  /  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 (8)  /  example  /  Controllers  
File Role Description
  Plain text file UserController.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:86
This week:0
All time:10,018
This week:74Up