lorenzo-d-alipio / basicrouter
Simple router forked from simonham with simple modifications
Requires
- php: >=5.4.0
This package is not auto-updated.
Last update: 2024-10-26 17:40:27 UTC
README
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.
Installation
This can be installed using composer.{
"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.
<?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));
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
Array ( [0] => test [1] => index [2] => method [3] => param_one [4] => param_two [5] => param_threee )
By writing a simple dispatcher, we can easily dispatch the controller/action + parameters (coming up soon).