dev-master
9999999-devEmerge PHP Routing
MIT
The Development Requires
by 高翔
0.1.1
0.1.1.0Emerge PHP Routing
MIT
The Development Requires
by 高翔
0.1.0
0.1.0.0Emerge PHP Routing
MIT
The Development Requires
by 高翔
Wallogit.com
2017 © Pedro Peláez
Emerge PHP Routing
一个基础的PHP路由, (*1)
composer require emerge/php-routing
use Emerge\Routing;
$routing = new Routing();
$routing->get(
'/admin',
['App\Admin', 'index']
);
$routing->get(
'/admin/user/$id',
['App\Admin', 'index'],
[
'requirements' => [
'id' => '\d+'
]
]
);
$result = $routing->dispatch('GET', '/admin/user/1');
print_r($result);
输出内容, (*2)
Array
(
[route] => /admin/user/$id
[callback] => Array
(
[0] => App\Admin
[1] => index
)
[options] => Array
(
[requirements] => Array
(
[id] => \d+
)
[method] => Array
(
[0] => GET
)
)
[parameters] => Array
(
[0] => /admin/user/1
[id] => 1
[1] => 1
)
)
VERSIONstring
版本号, (*3)
$routing::VERSION
get - 路由设置
array
get(string $route, array|callable $callback, [array $options = []])
返回添加的路由数据, (*4)
route, (*5)路由路径, (*6)
callback, (*7)路由回调,参考链接, (*8)
options, (*9)路由选项, 支持 requirements,method 两个选项, (*10)
Array
(
[route] => /admin/user/$id
[callback] => Array
(
[0] => App\Admin
[1] => index
)
[options] => Array
(
[requirements] => Array
(
[id] => \d+
)
[method] => Array
(
[0] => GET
)
)
)
$routing->get(
'/admin/user/$id',
['App\Admin', 'index'],
[
'method' => ['GET', 'POST']
'requirements' => [
'id' => '\d+'
]
]
);
dispatch - 分派路由
array
dispatch(string $method, string $uri)
返回路由分派结果, (*11)
method, (*12)HTTP方法, (*13)
uri, (*14)URI, (*15)
Array
(
[route] => /admin/user/$id
[callback] => Array
(
[0] => App\Admin
[1] => index
)
[options] => Array
(
[requirements] => Array
(
[id] => \d+
)
[method] => Array
(
[0] => GET
)
)
[parameters] => Array
(
[0] => /admin/user/1
[id] => 1
[1] => 1
)
)
$result = $routing->dispatch('GET', '/admin/user/1');
Emerge PHP Routing
MIT
Emerge PHP Routing
MIT
Emerge PHP Routing
MIT