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?
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.
Symfony 3+
use Symfony\Component\Routing\Generator\UrlGeneratorInterface;
$this->generateUrl('your_route_name', array('/* your route parameters */'), UrlGeneratorInterface::ABSOLUTE_URL);
请尝试以下方法:
$url = $this->generateUrl('your_route_name');
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.