@@ -59,6 +59,59 @@ parameter. This is not case-sensitive.
5959
6060.. literalinclude :: response/006.php
6161
62+ .. _response-redirect :
63+
64+ Redirect
65+ ========
66+
67+ If you want to create a redirect, use the :php:func: `redirect() ` function. It
68+ returns a ``RedirectResponse `` instance.
69+
70+ .. important :: If you want to redirect, an instance of ``RedirectResponse`` must
71+ be returned in a method of the :doc: `Controller <../incoming/controllers >` or
72+ the :doc: `Controller Filter <../incoming/filters >`. Note that the ``__construct() ``
73+ or the ``initController() `` method cannot return any value.
74+ If you forget to return ``RedirectResponse ``, no redirection will occur.
75+
76+ Redirect to a URI path
77+ ----------------------
78+
79+ When you want to pass a URI path (relative to baseURL), use ``redirect()->to() ``:
80+
81+ .. literalinclude :: ../general/common_functions/005.php
82+ :lines: 2-
83+
84+ .. note :: If there is a fragment in your URL that you want to remove, you can use the refresh parameter in this function.
85+ Like ``return redirect()->to('to', null, 'refresh'); ``.
86+
87+ Redirect to a Defined Route
88+ ---------------------------
89+
90+ When you want to pass a :ref: `route name <using-named-routes >` or Controller::method
91+ for :ref: `reverse routing <reverse-routing >`, use ``redirect()->route() ``:
92+
93+ .. literalinclude :: ../general/common_functions/013.php
94+ :lines: 2-
95+
96+ When passing an argument into the function, it is treated as a route name or
97+ Controller::method for reverse routing, not a relative/full URI,
98+ treating it the same as using ``redirect()->route() ``:
99+
100+ .. literalinclude :: ../general/common_functions/006.php
101+ :lines: 2-
102+
103+ Redirect Back
104+ -------------
105+
106+ When you want to redirect back, use ``redirect()->back() ``:
107+
108+ .. literalinclude :: ../general/common_functions/014.php
109+ :lines: 2-
110+
111+ .. note :: ``redirect()->back()`` is not the same as browser "back" button.
112+ It takes a visitor to "the last page viewed during the Session" when the Session is available.
113+ If the Session hasn’t been loaded, or is otherwise unavailable, then a sanitized version of HTTP_REFERER will be used.
114+
62115.. _force-file-download :
63116
64117Force File Download
0 commit comments