Changing URL in beforeRedirect() in Component - Cakephp 3

Posted on 05/23/2016 at 12:21 pm by Kevin Wentworth
Viewed 6,516 times | 0 comments

Change the URL redirect location using beforeRedirect() in Cakephp 3

I wanted to change the redirect behavior from within a component in my Cakephp 3 application.  The old 1.3 method of returning the new $url didn't work.  Turns out that you need to use Response::location() to modify the location of the redirect.  See my code below:

  1. public function beforeRedirect(Event $event, $url, Response $response) {
  2.         // need to reload the same page
  3.         $response->location($this->request->here);
  4.         return;
  5. }


Bookmark and Share

Tags for Changing URL in beforeRedirect() in Component - Cakephp 3

Cakephp | Cake3 | Web Programming

Comments for this Posting

No comments. Be the first to post a reply.

Sorry, comments are closed for this posting.

Please Email Kevin if you have any questions. Thanks!

Meet Site Avenger - Hosted Content Management System

Powered By: Site Avenger | Site Production: Saco Design