<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>

                ThinkChat2.0新版上線,更智能更精彩,支持會話、畫圖、視頻、閱讀、搜索等,送10W Token,即刻開啟你的AI之旅 廣告
                # 響應 / Response <p class="uk-article-lead">響應,即服務器發送給客戶端的 HTTP 響應。有兩種類型,在下面,每個都有一個例子來說明源自控制器操作的響應是怎么構建的。</p> [toc=2] ## 字符串 使用 `response` 服務返回簡單的字符串響應。 ```php public function indexAction() { return $this['response']->create('My content'); } ``` ## 已渲染的視圖 Pagekit 能渲染視圖并將相關的響應返回給你。只需要鍵 `$view` 設為包含標題(_title_)和視圖名稱(_name_)的數組,就能返回一個數組。 在數組中的所有其他參數,都可以在視圖中訪問。了解更多,請查閱[視圖 & 模板](224137)。 ```php public function indexAction($name = '') { return [ '$view' => [ 'title' => 'Hello World', 'name' => 'hello:views/index.php', ], 'name' => $name ]; } ``` 如果不想用它來渲染下面這種主題響應,在 `$view` 數組中設置 `'layout' => false`。 ## 主題/Themed 主題響應將控制器的結果繼承到由主題定義的布局中。只是簡單地從控制器返回一個字符串。 ```php public function indexAction() { return 'My content'; } ``` ## JSON 有兩種方式從控制器中返回 JSON 響應: 如果操作返回的是實現了 `\JsonSerializable` 的數組或對象,將會自動生成 `JsonResponse` 。 ```php public function jsonAction() { return ['error' => true, 'message' => 'There is nothing here. Move along.']; } ``` 當然, `response` 服務可以實現相同的事。 ```php public function jsonAction() { return $this['response']->json(['error' => true, 'message' => 'There is nothing here. Move along.']); } ``` ## 重定向 使用重定向響應對用戶進行重定向。 ```php public function redirectAction() { return $this['response']->redirect('@hello/greet/name', ['name' => 'Someone']); } ``` ## 自定義響應和錯誤頁面 使用 `create` 返回自定義 HTTP 響應。 ```php public function forbiddenAction() { return $this['response']->create('Permission denied.', 401); } ``` ## 流/Stream 流式響應允許將內容流式地返回到客戶端。它將回調函數作為它的第一個參數。在回調函數中,對 `flush` 的調用會被直接發送到客戶端。 ```php public function streamAction() { return $this['response']->stream(function() { echo 'Hello World'; flush(); echo 'Hello Pagekit'; flush(); }); } ``` ## 下載 下載響應讓你可以發送文件到客戶端。在大多數瀏覽器中,將 `Content-Disposition: attachment` 設為一個 _另存為/Save as_ 對話框。 ```php public function downloadAction() { return $this['response']->download('extensions/hello/extension.svg'); } ```
                  <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>

                              哎呀哎呀视频在线观看