是否有任何与 Aura 路由器和调度程序一起使用的示例/教程?我在文档页面上找到了示例代码:
// dispatch the request to the route handler.
// (consider using https://github.com/auraphp/Aura.Dispatcher
// in place of the one callable below.)
$callable = $route->handler;
$response = $callable($request);
// emit the response
foreach ($response->getHeaders() as $name => $values) {
foreach ($values as $value) {
header(sprintf('%s: %s', $name, $value), false);
}
}
http_response_code($response->getStatusCode());
echo $response->getBody();
我想知道如何将 Aura 调度程序与此示例代码集成。
第二个问题是当我们想使用 Aura 路由器检索 GET 请求时,我们使用如下内容:
// add a route to the map, and a handler for it
$map->get('blog.read', '/blog/{id}', function ($request) {
$id = (int) $request->getAttribute('id');
$response = new Zend\Diactoros\Response();
$response->getBody()->write("You asked for blog entry {$id}.");
return $response;
});
POST方法怎么样?我尝试了以下代码,但它无法以类似的方式检索名字:
$map->post('profile', '/profile', function ($request) {
$firstname = $request->getAttribute('firstname');
$response = new Zend\Diactoros\Response();
$response->getBody()->write("first name is {$firstname}");
return $response;
});
输出缺少 $firstname 值:
first name is