このページの2つのバージョン間の差分を表示します。
| 両方とも前のリビジョン 前のリビジョン 次のリビジョン | 前のリビジョン | ||
|
apricot:core:response-class [2020/05/05 10:14] y2sunlight [Apricot レスポンスクラス] |
apricot:core:response-class [2020/07/29 11:34] (現在) tanaka [RedirectResponseクラス] |
||
|---|---|---|---|
| 行 1: | 行 1: | ||
| - | > 編集中 | ||
| - | |||
| - | ----- | ||
| - | |||
| ====== Apricot レスポンスクラス ====== | ====== Apricot レスポンスクラス ====== | ||
| --- // | --- // | ||
| 行 17: | 行 13: | ||
| * [[apricot: | * [[apricot: | ||
| * Apricot レスポンスクラス | * Apricot レスポンスクラス | ||
| + | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| * [[apricot: | * [[apricot: | ||
| - | * [[apricot:app: | + | * [[apricot: |
| - | + | ||
| - | \\ | + | |
| HTTPレスポンスには以下の3ケースがあります。 | HTTPレスポンスには以下の3ケースがあります。 | ||
| 行 42: | 行 37: | ||
| |hasFlash(string $key): | |hasFlash(string $key): | ||
| |addFlash(string $key, $value): | |addFlash(string $key, $value): | ||
| - | |commit()|レスポンスの確定| | + | |commit(int $response_code=null)|レスポンスの確定| |
| {{fa> | {{fa> | ||
| 行 122: | 行 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 | ||
| 行 133: | 行 132: | ||
| header($header); | header($header); | ||
| } | } | ||
| + | |||
| + | // Save old URL Path | ||
| + | $this-> | ||
| // Output flashes | // Output flashes | ||
| 行 150: | 行 152: | ||
| ^メソッド^機能^ | ^メソッド^機能^ | ||
| - | |_ _construct(string $html=null)|RenderResponseの生成| | + | |< |
| |setHtml(string $html=null): | |setHtml(string $html=null): | ||
| - | |commit()|レスポンスの確定| | + | |commit(int $response_code=null)|レスポンスの確定| |
| - | + | ||
| - | <fs small>< | + | |
| {{fa> | {{fa> | ||
| 行 177: | 行 177: | ||
| * @param array $variables | * @param array $variables | ||
| */ | */ | ||
| - | public function | + | public function |
| { | { | ||
| $this-> | $this-> | ||
| 行 198: | 行 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('/ | ||
| 行 208: | 行 206: | ||
| $this-> | $this-> | ||
| } | } | ||
| + | |||
| + | parent:: | ||
| // HTMLのレンダリング | // HTMLのレンダリング | ||
| echo $this-> | echo $this-> | ||
| + | flush(); | ||
| } | } | ||
| } | } | ||
| 行 217: | 行 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テンプレートで良く使用されます。 | ||
| 行 238: | 行 237: | ||
| {{fa> | {{fa> | ||
| - | <code php RenderResponse.php> | + | <code php RedirectResponse.php> |
| <?php | <?php | ||
| namespace Core\Foundation\Response; | namespace Core\Foundation\Response; | ||
| 行 309: | 行 308: | ||
| \\ | \\ | ||
| - | ===== ヘルバー関数 ===== | + | ===== ヘルパー関数 ===== |
| レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。 | レスポンス処理用のヘルパー関数を追加します。render()とredirect()はコントローラアクションで、その他はHTMLテンプレートでよく使われる関数です。 | ||