<ruby id="bdb3f"></ruby>

    <p id="bdb3f"><cite id="bdb3f"></cite></p>

      <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
        <p id="bdb3f"><cite id="bdb3f"></cite></p>

          <pre id="bdb3f"></pre>
          <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

          <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
          <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

          <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                <ruby id="bdb3f"></ruby>

                合規國際互聯網加速 OSASE為企業客戶提供高速穩定SD-WAN國際加速解決方案。 廣告
                >[danger] 該組件為系統組件,在組件樹中只可命名為 response ,不可修改為其他名稱。 ## 響應 響應組件用來將控制器返回的數據、設置的HTTP報頭發送至客戶端。 | 類 | 調用 | 運行環境 | | --- | --- | --- | | Mix\Http\Message\Response\HttpResponse | app()->response | mix-httpd | | Mix\Http\Message\Response\Compatible\HttpResponse | app()->response | Apache/PHP-FPM | ## 依賴注入配置 [>> 到 GitHub 查看默認配置 <<](https://github.com/mix-php/mix/blob/v2/applications/http/config/main_coroutine.php#L184) 參數 `defaultFormat` 全部常量明細: - Mix\Http\Message\Response\HttpResponse::FORMAT_HTML - Mix\Http\Message\Response\HttpResponse::FORMAT_JSON - Mix\Http\Message\Response\HttpResponse::FORMAT_JSONP - Mix\Http\Message\Response\HttpResponse::FORMAT_XML ## 設置響應格式 當開發API接口時,通常需要響應 `JSON`、`JSONP`、`XML` 格式,這時可在控制中指定響應格式,代碼如下: ~~~ public function actionIndex() { app()->response->format = \Mix\Http\Message\Response\HttpResponse::FORMAT_JSON; return ['errcode' => 0, 'errmsg' => 'ok']; } ~~~ 也可以在App配置文件中的 `defaultFormat` 字段中定義默認的響應格式: ~~~ // 默認輸出格式 'defaultFormat' => Mix\Http\Message\Response\HttpResponse::FORMAT_JSON, ~~~ ## 重定向 重定向到首頁。 ~~~ app()->response->redirect('/'); ~~~ ## 設置狀態碼 ~~~ // 方法1 app()->response->statusCode = 404; // 方法2 app()->response->setStatusCode(404); ~~~ ## 設置響應格式 ~~~ // 方法1 app()->response->format = \Mix\Http\Message\Response\HttpResponse::FORMAT_JSON; // 方法2 app()->response->setFormat(\Mix\Http\Message\Response\HttpResponse::FORMAT_JSON); ~~~ ## 設置響應內容 ~~~ // 方法1 app()->response->content = '<html>...</html>'; // 方法2 app()->response->setContent('<html>...</html>'); ~~~ ## 設置報頭 ~~~ // 設置單個 app()->response->setHeader('Content-Type', 'application/json;charset=utf-8'); // 設置全部 app()->response->setHeaders(['Content-Type' => 'application/json;charset=utf-8']); ~~~ ## 設置 `Cookie` ~~~ app()->response->setCookie($name, $value, $expires, $path, $domain, $secure, $httpOnly); ~~~
                  <ruby id="bdb3f"></ruby>

                  <p id="bdb3f"><cite id="bdb3f"></cite></p>

                    <p id="bdb3f"><cite id="bdb3f"><th id="bdb3f"></th></cite></p><p id="bdb3f"></p>
                      <p id="bdb3f"><cite id="bdb3f"></cite></p>

                        <pre id="bdb3f"></pre>
                        <pre id="bdb3f"><del id="bdb3f"><thead id="bdb3f"></thead></del></pre>

                        <ruby id="bdb3f"><mark id="bdb3f"></mark></ruby><ruby id="bdb3f"></ruby>
                        <pre id="bdb3f"><pre id="bdb3f"><mark id="bdb3f"></mark></pre></pre><output id="bdb3f"></output><p id="bdb3f"></p><p id="bdb3f"></p>

                        <pre id="bdb3f"><del id="bdb3f"><progress id="bdb3f"></progress></del></pre>

                              <ruby id="bdb3f"></ruby>

                              哎呀哎呀视频在线观看