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 create a model in PHP Symfony?
- How to check PHP Symfony version?
- How to process async tasks in PHP Symfony?
- How to install PHP Symfony on Ubuntu?
- How to create a migration in PHP Symfony?
- How to do testing with PHP Symfony?
- How to integrate Vue.js with PHP Symfony?
- How to convert an object to an array in PHP Symfony?
- How to install Symfony on Windows?
- What are the required PHP Symfony extensions?
See more codes...