請按照文件「getting-started.md」中的步驟進行操作。
它幫助了我。
下面的代碼段允許路徑「/博客/(編號)」,其類似於以下URL在localhost:http://localhost/blog/42
$routerContainer = new RouterContainer();
$map = $routerContainer->getMap();
$map->get('blog.read', '/blog/{id}', function ($request, $response) {
$id = (int) $request->getAttribute('id');
echo "You asked for blog entry {$id}.<br/>";
httperror(200);
});
//
// ... Create more routes here ...
//
$request = Zend\Diactoros\ServerRequestFactory::fromGlobals(
$_SERVER, $_GET, $_POST, $_COOKIE, $_FILES
);
$matcher = $routerContainer->getMatcher();
$route = $matcher->match($request);
if (!$route) {
$failedRoute = $matcher->getFailedRoute();
switch ($failedRoute->failedRule) {
case 'Aura\Router\Rule\Allows':
httperror(405);
break;
case 'Aura\Router\Rule\Accepts':
httperror(406);
break;
default:
httperror(404);
break;
}
die();
}
foreach ($route->attributes as $key => $val) {
$request = $request->withAttribute($key, $val);
}
$response = new \Zend\Diactoros\Response;
$callable = $route->handler;
$response = $callable($request,$response);