Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get previous page route in Symfony?

Tags:

symfony-1.4

I am looking for way to do this in 'right' symfony way.

like image 769
VitalyP Avatar asked Apr 01 '11 09:04

VitalyP


1 Answers

There's a way to get the referer page from the $request variable. For example, if I was in myaction/mypage and click to myaction2/mypage2 by this getReferer() method I get 'http://myweb/myaction/mypage'.

If you are in an action method this can be done by

public function executeMyaction(sfWebRequest $request)
{
   $previousUrl = $request->getReferer();
   ...
}

if you are somewhere else you can get the request by getting the conext

$previousUrl = $this->getContext()->getRequest()->getReferer();

For for sfWebRequest methods check the sfWebRequest API.

Note: this value could be inaccesible using proxy's

like image 178
Pabloks Avatar answered Oct 02 '22 19:10

Pabloks