Symfony2 implements the method of obtaining the url in the controller, symfony2controller
This article describes the example of Symfony2 implementing the method of obtaining the url in the controller. Share it with everyone for your reference, the details are as follows:
// 假设当前URL地址是http://192.168.1.100/demo/web/app_dev.php/m/index
$request = $this->getRequest();
// http or https 此处为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 不一定是/demo/web/app_dev.php/m/index 取决于routeName
$this->generateUrl('routeName');
// routeName
$routeName = $request->get('_route');
I hope this article will be helpful to everyone’s PHP program design based on the Symfony framework.
Articles you may be interested in:
- Detailed examples of creating projects and template settings with the Symfony2 framework
- How to create projects using the symfony command
- Symfony page Detailed explanation of basic creation examples
- Analysis of date usage in twig of symfony2.4
- Summary of session and cookie usage in Symfony2
- Summary of the method of obtaining data from the database in Symfony2
- Detailed explanation of form usage of Symfony2 framework study notes
- Detailed explanation of HTTP Cache usage of Symfony2 framework study notes
- Plug-in format analysis of Symfony2 study notes
- Symfony2 study notes system Detailed explanation of routing
- Detailed explanation of controller usage in Symfony2 study notes
- Detailed explanation of template usage in Symfony2 study notes
- Detailed explanation of Symfony2 creation page instance
http://www.bkjia.com/PHPjc/1111907.htmlwww.bkjia.comtruehttp: //www.bkjia.com/PHPjc/1111907.htmlTechArticleSymfony2 implements the method of obtaining the url in the controller, symfony2controller This article describes the example of Symfony2 implementing the method of obtaining the url in the controller . Share it with everyone for your reference, specifically...
Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn