php-symfonyHow to get the current URL in PHP Symfony?
The current URL in PHP Symfony can be obtained using the getPathInfo() method of the Request object.
Example code
$request = Request::createFromGlobals();
$currentUrl = $request->getPathInfo();
Output example
/current/url
Code explanation
Request::createFromGlobals(): creates a new Request object from the PHP global variables.getPathInfo(): returns the path being requested relative to the executed script.
Helpful links
More of Php Symfony
- How to use Monolog in PHP Symfony?
- How to connect to MySQL in PHP Symfony?
- How to use websockets in PHP Symfony?
- How to generate QR Code in PHP Symfony?
- How to upload a file in PHP Symfony?
- How to do validation in PHP Symfony?
- How to send emails in Symfony with PHP?
- How to use mutex in PHP Symfony?
- How to run a command in PHP Symfony?
- How to use the Query Builder in PHP Symfony?
See more codes...