このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
| apricot:core:response-class [2020/06/03 12:03] tanaka [RenderResponseクラス] | apricot:core:response-class [2020/07/29 11:34] (現在) tanaka [RedirectResponseクラス] | ||
|---|---|---|---|
| 行 37: | 行 37: | ||
| |hasFlash(string $key): | |hasFlash(string $key): | ||
| |addFlash(string $key, $value): | |addFlash(string $key, $value): | ||
| - | |commit()|レスポンスの確定| | + | |commit(int $response_code=null)|レスポンスの確定| | 
| {{fa> | {{fa> | ||
| 行 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-> | + |  | 
| + | { | ||
| + | http_response_code($response_code); | ||
| + | } | ||
| // Output headers | // Output headers | ||
| 行 128: | 行 132: | ||
| header($header); | header($header); | ||
| } | } | ||
| + | |||
| + | // Save old URL Path | ||
| + | $this-> | ||
| // Output flashes | // Output flashes | ||
| 行 147: | 行 154: | ||
| |< | |< | ||
| |setHtml(string $html=null): | |setHtml(string $html=null): | ||
| - | |commit()|レスポンスの確定| | + | |commit(int $response_code=null)|レスポンスの確定| | 
| {{fa> | {{fa> | ||
| 行 191: | 行 198: | ||
| * @see \Core\Foundation\Response:: | * @see \Core\Foundation\Response:: | ||
| */ | */ | ||
| - | public function commit() | + | public function commit(int $response_code=null) | 
| { | { | ||
| - | parent:: | ||
| - | |||
| // headersに' | // headersに' | ||
| $matchs= preg_grep('/ | $matchs= preg_grep('/ | ||
| 行 201: | 行 206: | ||
| $this-> | $this-> | ||
| } | } | ||
| + | |||
| + | parent:: | ||
| // HTMLのレンダリング | // HTMLのレンダリング | ||
| echo $this-> | echo $this-> | ||
| + | flush(); | ||
| } | } | ||
| } | } | ||
| 行 210: | 行 218: | ||
| \\ | \\ | ||
| - | ==== RedirectResponseクラス ==== | + | ===== RedirectResponseクラス | 
| RedirectResponseクラスはResponseクラスから派生したリダイレクト用のクラスです。リダイレクトではフラッシュデータを使ってリダイレクト先のページにデータを送ることが多いので、フラッシュ用のメソッドが追加されています。RedirectResponseクラスは以下のメソッドを持ちます。addHeader()などのResponseクラスのメソッドも使用できます。 | RedirectResponseクラスはResponseクラスから派生したリダイレクト用のクラスです。リダイレクトではフラッシュデータを使ってリダイレクト先のページにデータを送ることが多いので、フラッシュ用のメソッドが追加されています。RedirectResponseクラスは以下のメソッドを持ちます。addHeader()などのResponseクラスのメソッドも使用できます。 | ||
| ^メソッド^機能^ | ^メソッド^機能^ | ||
| - | |_ _construct(string $url)|RedirectResponseの生成| | + | |< | 
| |with(string $key, $value): | |with(string $key, $value): | ||
| |withInputs(): | |withInputs(): | ||
| |withErrors(ErrorBag $errorBag): | |withErrors(ErrorBag $errorBag): | ||
| |withOldErrors(): | |withOldErrors(): | ||
| - | |||
| - | <fs small>< | ||
| 以下は、レスポンスで使用するフラッシュデータのキーとその内容です。特に _old_inputs と errors はHTMLテンプレートで良く使用されます。 | 以下は、レスポンスで使用するフラッシュデータのキーとその内容です。特に _old_inputs と errors はHTMLテンプレートで良く使用されます。 | ||
| 行 231: | 行 237: | ||
| {{fa> | {{fa> | ||
| - | <code php RenderResponse.php> | + | <code php RedirectResponse.php> | 
| <?php | <?php | ||
| namespace Core\Foundation\Response; | namespace Core\Foundation\Response; | ||
| 行 302: | 行 308: | ||
| \\ | \\ | ||
| - | ===== ヘルバー関数 ===== | + | ===== ヘルパー関数 ===== | 
| レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。 | レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。 | ||