Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get current URI from Symfony 1.4?

I am new to symfony.

How can I get from Symfony 1.4 the URI path ?

I have tryied like that:

sfContext::getInstance()->getRequest()->getRelativeUrlRoot()

but is not working.

like image 678
radu c Avatar asked May 23 '11 16:05

radu c


2 Answers

getCurrentInternalUri is, like his name tell, the internal URL, to be used in internal routing functions such as link_to.

The question is about the current URI and even if the previous answer is marked as accepted, here is the method to fetch the current URI in symfony 1.4.

$context->getRequest()->getUri();

In an action :

public function executeDelete(sfWebRequest $request)
{
  $uri = $request->getUri();
}
like image 121
Damien Avatar answered Nov 20 '22 00:11

Damien


Like this:

sfContext::getInstance()->getRouting()->getCurrentInternalUri();

This one might be of use too:

sfContext::getInstance()->getRouting()->getCurrentRouteName();

http://www.symfony-project.org/gentle-introduction/1_4/en/09-Links-and-the-Routing-System#chapter_09_dealing_with_routes_in_actions

UPDATE:

Please see Damien's answer below and im3r3k's comment for what seems to be a better method as it does not rely on context.

like image 12
Tom Avatar answered Nov 19 '22 23:11

Tom