Skip to content

Commit 77d29b8

Browse files
authored
Merge pull request #6564 from cakephp/redirect-docs
Add RedirectException docs
2 parents b03f5e5 + 0dbb077 commit 77d29b8

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

en/appendices/4-1-migration-guide.rst

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ ORM
4242
* ``QueryExpression::or_()`` and ``QueryExpression::and_()`` have been
4343
deprecated. Use ``or()`` and ``and()`` instead.
4444

45+
Routing
46+
-------
47+
48+
* ``Cake\Routing\Exception\RedirectException`` is deprecated. Use
49+
``Cake\Http\Exception\RedirectException`` instead.
50+
4551
View
4652
----
4753

@@ -70,7 +76,7 @@ ORM
7076

7177
* BelongsToMany associations now respect the bindingKey set in the junction table's BelongsTo association.
7278
Previously, the target table's primary key was always used instead.
73-
79+
7480
TestSuite
7581
---------
7682

@@ -113,6 +119,17 @@ Error
113119
respectively.
114120
* The ``Debugger.editor`` configure value has been added. This value is used as
115121
the preferred editor link format.
122+
* ``ErrorHandlerMiddleware`` now handles
123+
``Http\Exception\RedirectException`` and converts those exceptions into HTTP
124+
redirect responses.
125+
126+
Http
127+
----
128+
129+
* ``Cake\Http\Exception\RedirectException`` was added. This exception replaces
130+
the ``RedirectException`` in the Routing package and can be raised anywhere in
131+
your application to signal to the error handling middleware to create
132+
a redirect response.
116133

117134
Log
118135
---

en/controllers/components.rst

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,26 @@ To redirect from within a component callback method you can use the following::
321321

322322
By stopping the event you let CakePHP know that you don't want any other
323323
component callbacks to run, and that the controller should not handle the action
324-
any further.
324+
any further. As of 4.1.0 you can raise a ``RedirectException`` to signal
325+
a redirect::
326+
327+
use Cake\Http\Exception\RedirectException;
328+
use Cake\Routing\Router;
329+
330+
public function beforeFilter(EventInterface $event)
331+
{
332+
throw new RedirectException(Router::url('/'))
333+
}
334+
335+
Raising an exception will halt all other event listeners and create a new
336+
response that doesn't retain or inherit any of the current response's headers.
337+
When raising a ``RedirectException`` you can include additional headers::
338+
339+
throw new RedirectException(Router::url('/'), 302, [
340+
'Header-Key' => 'value',
341+
]);
342+
343+
.. versionadded:: 4.1.0
325344

326345
.. meta::
327346
:title lang=en: Components

0 commit comments

Comments
 (0)