2017 © Pedro Peláez
 

library basicrouter

Simple router forked from simonham with simple modifications

image

lorenzo-d-alipio/basicrouter

Simple router forked from simonham with simple modifications

  • Thursday, August 31, 2017
  • by lorenzo Alipio
  • Repository
  • 1 Watchers
  • 1 Stars
  • 3 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 1 Forks
  • 0 Open issues
  • 1 Versions
  • 0 % Grown

The README.md

basicrouter

This router is based on simonhamp/routes of which I forked months ago. There is nothing wrong about the original router. However, I decided to add another method to extract the controller and the controller method from the route() shown in the original class. , (*1)

Installation

This can be installed using composer., (*2)


{

    "require":{
                  "basicrouter": "dev-master"
                
        },
       "repositories": [
   
   {
    "type": "vcs",
    "url": "https://github.com/Bryan-D-Lee/basicrouter"

   }
   ]  
        
}
                

If you install it via composer, make sure to add namespace on top of the Router class. , (*3)


<?php namespace System\Libraries;


Example of composer installed


<?php

require_once(__DIR__ .'/vendor/autoload.php');

$routes = array(
       
        'controller/(:any)/(:any)/(:any)' => 'test/index/$1/$2/$3/',
        'register/' => 'MyController/myController_action'

        );
        
$url = 'dir/controller/method/param_one/param_two/param_threee';
$default_dir = ('dir/');
$request = trim(str_replace($default_dir, '', $url));       
        
System\Libraries\Router::add($routes);
$action_request = System\Libraries\Router::route($request);

print_r(array_filter($action_request));


, (*4)

Alternative installation example


<?php

include('Router.php');

$routes = array(
       
        'controller/(:any)/(:any)/(:any)' => 'test/index/$1/$2/$3/',
        'register/' => 'MyController/myController_action'

        );
        
$url = 'dir/controller/method/param_one/param_two/param_threee';
$default_dir = ('dir/');
$request = trim(str_replace($default_dir, '', $url));       
        
Router::add($routes);
$action_request = Router::route($request);

print_r(array_filter($action_request));


The above examples should return something like this, (*5)

Array ( [0] => test [1] => index [2] => method [3] => param_one [4] => param_two [5] => param_threee ) , (*6)

By writing a simple dispatcher, we can easily dispatch the controller/action + parameters (coming up soon)., (*7)

The Versions

31/08 2017

dev-master

9999999-dev https://github.com/Lorenzo-D-Alipio/basicrouter

Simple router forked from simonham with simple modifications

  Sources   Download

MIT

The Requires

  • php >=5.4.0

 

by Credit: Simon Hamp
by Lorenzo De Leon Alipio

php routing