How to get the referer url in symfony redirection
I can suggest you to put the referer inside the session to be able to retrieve after your redirect. This how sfGuard perform it.
Before your redirect:
// save the referer
$referer = $this->getContext()->getActionStack()->getSize() > 1 ? $request->getUri() : $request->getReferer();
$this->getUser()->setAttribute('referer', $referer);
// make your redirect
$this->redirect('module2/action2');
Then, in your module2/action2
, retrieve your referer like that:
$referer = $this->getUser()->getAttribute('referer');
// finally, remove it from session
$this->getUser()->getAttributeHolder()->remove('referer');
Thilanka
I'm a computer science undergraduate at Department of university of Moratuwa, Sri Lanka. I'm interested on image processing, web developing and the back end java programming.
Updated on June 04, 2022Comments
-
Thilanka almost 2 years
I'm using symfony 1.4 for some web application. In there when someone try to access one action I'm redirecting it to a new action as follows.
//Assume I'm redecting from module1/action1 to module2/action2 $this->redirect('module2/action2');
I in the module2/action2 can I get the url where it get redirected. I used
$request->getReferer();
But it doesn't give any result.
I don't need to use forward instead of redirect because it doesn't match for my need. Can someone help me on this.
-
Thilanka over 11 yearsSo where do we need to do this. Is it at a filter or somewhere.
-
j0k over 11 yearsNope, you can put every thing in your action
-
Thilanka over 11 yearsYes but then every action we have to put. It won't be a generic place where we can refer.
-
Sébastien almost 9 yearsextend your controller by a custom one where yo put this