dev-master
9999999-dev https://github.com/Lorenzo-D-Alipio/basicrouterSimple router forked from simonham with simple modifications
MIT
The Requires
- php >=5.4.0
by Credit: Simon Hamp
by Lorenzo De Leon Alipio
php routing
Wallogit.com
2017 © Pedro Peláez
Simple router forked from simonham with simple modifications
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)
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;
<?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)
<?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)
Simple router forked from simonham with simple modifications
MIT
php routing