Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I redirect to previous page in zend framework 2?

For these situations, I want to auto redirect back to the pages from where I made the request:

  1. After finishing any action (CRUD etc) - Here I think we need to redirect to 'HTTP_REFERER'
  2. While surfing or shopping, if login required, so after finishing authentication process, it should redirect back to the same page

A different situation (which is not 'redirect to previous page'):

  • Pass a redirect URL (landing page address) in query, for eg: If I send a (external)/URL (ofc encoded) in as GET query parameter (or route part), after login, it should redirect me to this URL

I have already searched over net for this and found some solutions but they are not according to Zend Framework 2. I want all this to be done in zf2 way.

Thanks for any help!

like image 849
Sanju Avatar asked Jan 13 '13 12:01

Sanju


1 Answers

This worked for me:

$url = $this->getRequest()->getHeader('Referer')->getUri();
$this->redirect()->toUrl($url);
like image 116
hohner Avatar answered Sep 18 '22 20:09

hohner