Skip to content

Commit ef1650c

Browse files
committed
Finished databases guide
1 parent 37fa205 commit ef1650c

File tree

3 files changed

+266
-49
lines changed

3 files changed

+266
-49
lines changed

src/guide/runtime/response.md

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -97,9 +97,20 @@ return $response
9797
->withHeader('Location', 'https://www.example.com');
9898
```
9999

100+
Note that there are different statuses used for redirection:
101+
102+
| Code | Usage | What is it for |
103+
|------|------------------------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
104+
| 301 | `Status::MOVED_PERMANENTLY` | Permanently changed a URL structure. Search engines update their indexes, and browsers cache it. |
105+
| 308 | `Status::PERMANENT_REDIRECT` | Like 301, but guarantees the HTTP method won't change. |
106+
| 302 | `Status::FOUND` | Temporary changes like maintenance pages. Original URL should still be used for future requests. Search engines typically don't update their indexes. |
107+
| 307 | `Status::TEMPORARY_REDIRECT` | Like 302, but guarantees the HTTP method won't change. |
108+
| 303 | `Status::SEE_OTHER` | After form submissions to prevent duplicate submissions if the user refreshes. Explicitly tells to use `GET` for the redirect, even if the original request was `POST`. |
109+
100110
### Responding with JSON
101111

102112
```php
113+
use Yiisoft\Http\Status;
103114
use Yiisoft\Json\Json;
104115

105116
$data = [
@@ -109,6 +120,6 @@ $data = [
109120

110121
$response->getBody()->write(Json::encode($data));
111122
return $response
112-
->withStatus(200)
113-
->withHeader('Content-Type', 'application/json');
123+
->withStatus(Status::OK)
124+
->withHeader('Content-Type', 'application/json');
114125
```

0 commit comments

Comments
 (0)