phpalchemy / routing
PHP Alchemy 路由组件
v1.0
2013-09-03 20:59 UTC
Requires
- php: >=5.3.3
This package is not auto-updated.
Last update: 2024-09-23 15:51:05 UTC
README
更快的简单 HTTP 路由
这是一个简单但更快的 URL HTTP 路由库
示例用法
use Alchemy\Component\Routing\Mapper;
use Alchemy\Component\Routing\Route;
$mapper = new Mapper();
$mapper->connect(
'home_route',
new Route(
'/',
array(
'_controller' => 'sample',
'_action' => 'index'
)
)
);
$mapper->connect(
'to_index_route',
new Route(
'/{_controller}',
array('_action' => 'index')
)
);
$mapper->connect(
'complete_route',
new Route(
'/{_controller}/{_action}'
)
);
$mapper->connect(
'complete_route',
new Route(
'/leap_year/{year}', // pattern
array( // defaults
'_controller' => 'Validator',
'_action' => 'leapYear'
),
array( // requeriments
'year' => '\d+',
'_method' => array('GET', 'POST')
)
)
);
print_r($mapper->match('/home/sample'));
Array
(
[_controller] => home,
[_action] => sample
)
print_r($mapper->match('/leap_year/2012'));
Array
(
[_controller] => Validator,
[_action] => leapYear,
[year] => 2012,
)