I am designing a website, that has my groups and other groups that are present on two different webpages. Both my groups and other groups have an option to see the members of each group which is redirecting to a
You could use the redirect plugin and add a query param
previous to the url. Check this answer for an example and check the ZF2 documentation here on the redirect plugin. It would become something like this:
In the controller for your
my_groups route where you added the redirect url to your members page you will need to add the query param to the redirect route:
$previous = 'my_groups'; $this->redirect()->toRoute( 'members', array( 'action' => 'index' ), array( 'query' => array( 'previous' => $previous )) );
Now when the
members.phtml page is requested you can find the previous page inside the query parameters of the request object. You can easily access it in your controller like this:
$previous = $this->params()->fromQuery('previous'); // my_groups
Now you know whether the members page was accessed from
other_groups and you can render the back button accordingly.
Some extra information after your comment...
You can find current page url for example by using:
Or you can get the current matched route:
And you can use this to dynamically add the previous url.