<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國際加速解決方案。 廣告
                ## Yaf官方響應類可以參考: http://www.laruence.com/manual/yaf.class.response.html http://php.net/manual/zh/class.yaf-response-abstract.php ## 響應類 ### Yaf\Response\Http Yaf\Response\Http 是在Yaf作為Web應用的時候默認響應載體。因繼承自Yaf\Response_Abstract, 所以Yaf\Response_Abstract有的方法該類里也有。 ``` final Yaf\Response\Http extends Yaf\Response_Abstract { public $_response_code; // 響應給請求端的HTTP狀態碼 } ``` ### Yaf\Response\Cli Yaf\Response\Cli是在Yaf作為命令行應用的時候默認響應載體。 因繼承自Yaf\Response_Abstract, 所以Yaf\Response_Abstract有的方法該類里也有。 ``` final Yaf\Response\Cli extends Yaf\Response_Abstract { } ``` ### Yaf\Response\Http 和 Yaf\Response\Cli比較 通過使用var_dump(get_class_methods(Yaf\Response\Http::class)); 得出: ``` array (size=14) 0 => string 'setHeader' (length=9) 1 => string 'setAllHeaders' (length=13) 2 => string 'getHeader' (length=9) 3 => string 'clearHeaders' (length=12) 4 => string 'setRedirect' (length=11) 5 => string 'response' (length=8) 6 => string '__construct' (length=11) 7 => string '__destruct' (length=10) 8 => string '__toString' (length=10) 9 => string 'setBody' (length=7) 10 => string 'appendBody' (length=10) 11 => string 'prependBody' (length=11) 12 => string 'clearBody' (length=9) 13 => string 'getBody' (length=7) ``` 通過使用var_dump(get_class_methods(Yaf\Response\Cli::class)); 得出 ``` array (size=9) 0 => string '__construct' (length=11) 1 => string '__destruct' (length=10) 2 => string '__toString' (length=10) 3 => string 'setBody' (length=7) 4 => string 'appendBody' (length=10) 5 => string 'prependBody' (length=11) 6 => string 'clearBody' (length=9) 7 => string 'getBody' (length=7) 8 => string 'response' (length=8) ``` 對比后我們可以發現, Yaf\Response\Http 比 Yaf\Response\Cli的多了 header相關的方法: > setHeader > setAllHeaders > getHeader > clearHeaders ## 類方法 ### response #### 需要注意的是,默認情況下,$this->getResponse()->response()方法是會被自動調用的,如果手動調用,會導致最終被調用兩次。 如果想顯式調用response()方法,需要顯式配置下: ``` Yaf\Dispatcher::getInstance()->returnResponse(true); ``` 例如 ``` <?php $application = new Yaf\Application("config.ini"); /** 關閉自動響應, 由開發自己顯式調用輸出 */ $response = $application->getDispatcher()->returnResponse(TRUE)->getApplication()->run(); /** 輸出響應*/ $response->response(); ?> ``` ### setBody 設置響應的Body ``` public bool Yaf\Response_Abstract::setBody ( string $content [, string $key ] ) ``` $content: 是我們要傳入的業務數據 $key: body所對應的key,你可以設置一個body的鍵值對,如果你沒有指定key,系統默認使用Yaf\Response_Abstract::DEFAULT_BODY $key 參數因為是最終調用一次,所以一般不用額外傳值。 例如 ``` <?php class IndexController extends Yaf\Controller_Abstract { public function testAction() { Yaf\Dispatcher::getInstance()->autoRender(false); $data = ['code' => 0, 'msg'=>'SUCCESS', 'data' => ['uid'=>1, 'name' => 'test']]; // 你的業務數據 $result = json_encode($data); $response = $this->getResponse(); $response->setBody($result); } } ``` ### setHeader 設置響應的header頭信息 ``` public bool Yaf\Response_Abstract::setHeader ( string $name , string $value [, bool $replace ] ) ``` 例如 ``` <?php class IndexController extends Yaf\Controller_Abstract { public function testAction() { Yaf\Dispatcher::getInstance()->autoRender(false); $data = ['code' => 0, 'msg'=>'SUCCESS', 'data' => ['uid'=>1, 'name' => 'test']]; // 你的業務數據 $result = json_encode($data); $response = $this->getResponse(); $response->setHeader('Yaf-Version', "3.0.4"); $response->setBody($result); } } ``` ### setAllHeaders 批量設置響應的header頭信息 ``` public bool Yaf\Response_Abstract::setAllHeaders ( array $headers) ``` 例如 ``` <?php class IndexController extends Yaf\Controller_Abstract { public function testAction() { Yaf\Dispatcher::getInstance()->autoRender(false); $data = ['code' => 0, 'msg'=>'SUCCESS', 'data' => ['uid'=>1, 'name' => 'test']]; // 你的業務數據 $result = json_encode($data); $response = $this->getResponse(); $headers = ['Yaf-Version' => "3.0.4", "X-HOST"=>"10.10.10.10"]; $response->setAllHeaders($headers); $response->setBody($result); } } ``` ### getHeader 獲取請求的header頭信息 ``` public void Yaf\Response_Abstract::getHeader ( void) ``` 例如 ``` <?php class IndexController extends Yaf\Controller_Abstract { public function testAction() { Yaf\Dispatcher::getInstance()->autoRender(false); $data = ['code' => 0, 'msg'=>'SUCCESS', 'data' => ['uid'=>1, 'name' => 'test']]; // 你的業務數據 $result = json_encode($data); $response = $this->getResponse(); $headers = ['Yaf-Version' => "3.0.4", "X-HOST"=>"10.10.10.10"]; $response->setAllHeaders($headers); var_dump($response->getHeader()); } } ``` ### clearHeaders ### getBody 獲取body內容 ``` <?php $response = $this->getResponse(); $response->setBody("Hello")->setBody(" World", "footer"); var_dump($response->getBody()); //Hello var_dump($response->getBody(Yaf\Response_Abstract::DEFAULT_BODY::DEFAULT_BODY)); //Hello 和上面的一樣 var_dump($response->getBody("footer")); // World var_dump($response->getBody(NULL)); //get all ?> ``` ### clearBody ### appendBody ### prependBody
                  <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>

                              哎呀哎呀视频在线观看