Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Symfony2: Full path to action/route in a controller

I need the full path to a action inside my controller, to send it via email. How can I achieve something like {{ path('_route') }} from inside my controller but the full path?

like image 574
Fabian Avatar asked Nov 01 '12 01:11

Fabian


3 Answers

Juan's answer is right if you want the local path. The absolute path — which is helpful to be send through email — needs extra parameter(s):

$url = $this->generateUrl('your_route_name', array(), true);

The third parameter indicates that the absolute path is to be generated.

If you want to use this URL in your view just add the $url to the response array in your action and use it.

like image 150
Alberto Gaona Avatar answered Nov 07 '22 19:11

Alberto Gaona


Symfony 3+

use Symfony\Component\Routing\Generator\UrlGeneratorInterface;

$this->generateUrl('your_route_name', array('/* your route parameters */'), UrlGeneratorInterface::ABSOLUTE_URL);
like image 39
Saman Mohamadi Avatar answered Nov 07 '22 20:11

Saman Mohamadi


Try the following:

$url = $this->generateUrl('your_route_name');
like image 25
Juan Sosa Avatar answered Nov 07 '22 18:11

Juan Sosa