File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -571,6 +571,28 @@ for best results::
571
571
572
572
.. _controller-middleware :
573
573
574
+ Using Redirects in Controller Events
575
+ ====================================
576
+
577
+ To redirect from within a controller callback method you can use the following::
578
+
579
+ public function beforeFilter(EventInterface $event): void
580
+ {
581
+ if (...) {
582
+ $event->setResult($this->redirect('/'));
583
+
584
+ return;
585
+ }
586
+
587
+ ...
588
+ }
589
+
590
+ By setting a redirect as event result you let CakePHP know that you don't want any other
591
+ component callbacks to run, and that the controller should not handle the action
592
+ any further.
593
+
594
+ As of 4.1.0 you can also raise a ``RedirectException `` to signal a redirect.
595
+
574
596
Controller Middleware
575
597
=====================
576
598
Original file line number Diff line number Diff line change @@ -346,7 +346,7 @@ To redirect from within a component callback method you can use the following::
346
346
...
347
347
}
348
348
349
- By stopping the event you let CakePHP know that you don't want any other
349
+ By setting a redirect as event result you let CakePHP know that you don't want any other
350
350
component callbacks to run, and that the controller should not handle the action
351
351
any further. As of 4.1.0 you can raise a ``RedirectException `` to signal
352
352
a redirect::
You can’t perform that action at this time.
0 commit comments