Ground Sunlight

Windowsで作る - PHPプログラミングの開発環境

ユーザ用ツール

サイト用ツール


apricot:core:response-class

差分

このページの2つのバージョン間の差分を表示します。

この比較画面にリンクする

両方とも前のリビジョン 前のリビジョン
次のリビジョン
前のリビジョン
apricot:core:response-class [2020/06/03 12:07]
tanaka [RedirectResponseクラス]
apricot:core:response-class [2020/07/29 11:34] (現在)
tanaka [RedirectResponseクラス]
行 37: 行 37:
 |hasFlash(string $key):bool|フラッシュデータの存在確認| |hasFlash(string $key):bool|フラッシュデータの存在確認|
 |addFlash(string $key, $value):Response|フラッシュデータの追加| |addFlash(string $key, $value):Response|フラッシュデータの追加|
-|commit()|レスポンスの確定|+|commit(int $response_code=null)|レスポンスの確定|
  
 {{fa>folder-open-o}} ** /apricot/core/Foundation ** {{fa>folder-open-o}} ** /apricot/core/Foundation **
行 117: 行 117:
     /**     /**
      * Commit Response Data      * Commit Response Data
 +     * @param int $response_code
      */      */
-    public function commit()+    public function commit(int $response_code=null)
     {     {
-        // Save old URL Path +        // Set Http response code 
-        $this->addFlash(self::FLASH_KEY_BACK, $_SERVER['REQUEST_URI']);+        if (isset($response_code)) 
 +        { 
 +            http_response_code($response_code); 
 +        }
  
         // Output headers         // Output headers
行 128: 行 132:
             header($header);             header($header);
         }         }
 +
 +        // Save old URL Path
 +        $this->addFlash(self::FLASH_KEY_BACK, $_SERVER['REQUEST_URI']);
  
         // Output flashes         // Output flashes
行 147: 行 154:
 |<nowiki>__</nowiki>construct(string $html=null)|RenderResponseの生成| |<nowiki>__</nowiki>construct(string $html=null)|RenderResponseの生成|
 |setHtml(string $html=null):RenderResponse|HTMLテキストの設定| |setHtml(string $html=null):RenderResponse|HTMLテキストの設定|
-|commit()|レスポンスの確定|+|commit(int $response_code=null)|レスポンスの確定|
  
 {{fa>folder-open-o}} ** /apricot/core/Foundation/Response ** {{fa>folder-open-o}} ** /apricot/core/Foundation/Response **
行 191: 行 198:
      * @see \Core\Foundation\Response::commit()      * @see \Core\Foundation\Response::commit()
      */      */
-    public function commit()+    public function commit(int $response_code=null)
     {     {
-        parent::commit(); 
- 
         // headersに'Content-type'がなければ出力する         // headersに'Content-type'がなければ出力する
         $matchs= preg_grep('/^content-type.*?:/i', $this->headers);         $matchs= preg_grep('/^content-type.*?:/i', $this->headers);
行 201: 行 206:
             $this->addHeader("Content-type: text/html; charset=utf-8");             $this->addHeader("Content-type: text/html; charset=utf-8");
         }         }
 +
 +        parent::commit($response_code);
  
         // HTMLのレンダリング         // HTMLのレンダリング
         echo $this->html;         echo $this->html;
 +        flush();
     }     }
 } }
行 210: 行 218:
 \\ \\
  
-==== RedirectResponseクラス ====+===== RedirectResponseクラス =====
  
 RedirectResponseクラスはResponseクラスから派生したリダイレクト用のクラスです。リダイレクトではフラッシュデータを使ってリダイレクト先のページにデータを送ることが多いので、フラッシュ用のメソッドが追加されています。RedirectResponseクラスは以下のメソッドを持ちます。addHeader()などのResponseクラスのメソッドも使用できます。 RedirectResponseクラスはResponseクラスから派生したリダイレクト用のクラスです。リダイレクトではフラッシュデータを使ってリダイレクト先のページにデータを送ることが多いので、フラッシュ用のメソッドが追加されています。RedirectResponseクラスは以下のメソッドを持ちます。addHeader()などのResponseクラスのメソッドも使用できます。
行 229: 行 237:
  
 {{fa>folder-open-o}} ** /apricot/core/Foundation/Response ** {{fa>folder-open-o}} ** /apricot/core/Foundation/Response **
-<code php RenderResponse.php>+<code php RedirectResponse.php>
 <?php <?php
 namespace Core\Foundation\Response; namespace Core\Foundation\Response;
行 300: 行 308:
 \\ \\
  
-===== ヘルー関数 =====+===== ヘルー関数 =====
  
 レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。 レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。
apricot/core/response-class.1591153648.txt.gz · 最終更新: 2020/06/03 12:07 by tanaka