@@ -64,8 +64,15 @@ parameter. This is not case-sensitive.
64
64
Redirect
65
65
========
66
66
67
- If you want to create a redirect, use the :php:func: `redirect() ` function. It
68
- returns a ``RedirectResponse `` instance.
67
+ If you want to create a redirect, use the :php:func: `redirect() ` function.
68
+
69
+ It returns a ``RedirectResponse `` instance. It is a different instance from the
70
+ global response instance that ``Services::response() `` returns.
71
+
72
+ .. warning :: If you set Cookies or Response Headers before you call ``redirect()``,
73
+ they are set to the global response instance, and they are not automatically
74
+ copied to the ``RedirectResponse `` instance. To send them, you need to call
75
+ the ``withCookies() `` or ``withHeaders() `` method manually.
69
76
70
77
.. important :: If you want to redirect, an instance of ``RedirectResponse`` must
71
78
be returned in a method of the :doc: `Controller <../incoming/controllers >` or
@@ -113,6 +120,30 @@ When you want to redirect back, use ``redirect()->back()``:
113
120
It takes a visitor to "the last page viewed during the Session" when the Session is available.
114
121
If the Session hasn't been loaded, or is otherwise unavailable, then a sanitized version of HTTP_REFERER will be used.
115
122
123
+ Redirect with Cookies
124
+ ---------------------
125
+
126
+ If you set Cookies before you call ``redirect() ``, they are set to the global
127
+ response instance, and they are not automatically copied to the ``RedirectResponse ``
128
+ instance.
129
+
130
+ To send the Cookies, you need to call the ``withCookies() `` method manually.
131
+
132
+ .. literalinclude :: ./response/034.php
133
+ :lines: 2-
134
+
135
+ Redirect with Headers
136
+ ---------------------
137
+
138
+ If you set Response Headers before you call ``redirect() ``, they are set to the
139
+ global response instance, and they are not automatically copied to the
140
+ ``RedirectResponse `` instance.
141
+
142
+ To send the Headers, you need to call the ``withHeaders() `` method manually.
143
+
144
+ .. literalinclude :: ./response/035.php
145
+ :lines: 2-
146
+
116
147
.. _response-redirect-status-code :
117
148
118
149
Redirect Status Code
0 commit comments