How to redirect user to previous page in Zend Framework 2.5

Hi guys! In this tutorial I will explain how you can redirect user to previous page in Zend Framework 2.5.

As you might know, if you want to redirect users to an action, you can use this code:

$this->redirect()->toRoute(array('controller' => 'yourcontroller','action' => 'youraction'))

But if you want to redirect user to previous page, you have to write this code in your controller:

$url = $_SERVER['HTTP_REFERER'];

$this->redirect()->toUrl($url);

You can use this code to redirect users after comment submission or after other actions!









Leave a Comment