# 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.
- 開始
- 安裝
- 升級指南
- Web服務器
- 概念
- 生命周期
- PSR 7
- 中間件
- 依賴容器
- 實例 及通知和警告處理
- Request
- 請求方法
- 請求頭信息
- 請求主體
- 上傳的文件
- 請求幫助
- 路由對象
- Response
- 響應狀態
- 響應標頭
- 響應體
- 返回JSON
- 視圖模板
- 路由
- 創建路由
- 路由回調
- 路由策略
- 路線占位符
- 路由名
- 路由組
- 路由中間件
- 路由表達式緩存
- 容器識別解析
- 封裝中間件
- 路由的中間件
- 錯誤處理中間件
- 方法重寫的中間件
- 輸出緩沖中間件
- 內容長度中間件
- 擴展功能
- 以 / 結尾的路由模式
- 獲取當前路由
- 設置CORS
- 使用POST表單上傳文件
- 第三方組件
- slim-session
- auth
- slim-api-skeleton
- dir