多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
# Response Your Slim app’s routes and middleware are given a PSR-7 response object that represents the current HTTP response to be returned to the client. The response object implements the[PSR-7 ResponseInterface](http://www.php-fig.org/psr/psr-7/#3-2-1-psr-http-message-responseinterface)with which you can inspect and manipulate the HTTP response status, headers, and body. > Slim应用程序的路由和中间件都有一个PSR-7响应对象,该对象表示当前要返回给客户机的HTTP响应。response对象实现了[PSR-7 ResponseInterface](http://www.php-fig.org/psr/psr-7/#3-2-1-psr-http-message-responseinterface),您可以使用该对象检查和操作HTTP响应状态、头和正文。 ## 如何获取响应对象 The PSR-7 response object is injected into your Slim application routes as the second argument to the route callback like this: > 将PSR-7响应对象作为路由回调的第二个参数注入到slim应用程序路由中,如下所示: ~~~php <?php use Psr\Http\Message\ResponseInterface as Response; use Psr\Http\Message\ServerRequestInterface as Request; use Slim\Factory\AppFactory; require __DIR__ . '/../vendor/autoload.php'; $app = AppFactory::create(); $app->get('/hello', function (ServerRequest $request, Response $response) { $response->getBody()->write('Hello World'); return $response; }); $app->run(); ~~~ Figure 1: Inject PSR-7 response into application route callback.