This article mainly introduces how to obtain a url in the controller by using Symfony2. the instance analyzes common methods and usage skills for obtaining a URL by using Symfony, for more information about how to obtain a url in the controller, see the example in this article. We will share this with you for your reference. The details are as follows:
// Assume that the current URL is http: // 192.168.1.100/demo/web/app_dev.php/m/index $ request = $ this-> getRequest (); // http or https here is http $ request-> getScheme (); // 192.168.1.100 $ request-> getHttpHost (); // http: // 192.168.1.100 $ request-> getSchemeAndHttpHost (); // demo/web/$ request-> getBasePath (); // demo/index. php $ request-> getBaseUrl (); // eg: /demo/web/app_dev.php/user/login is not necessarily/demo/web/app_dev.php/m/index depends on routeName $ this-> generateUrl ('routename '); // routeName $ routeName = $ request-> get ('_ route ');
I hope this article will help you design PHP programs based on the Symfony framework.