Home  >  Article  >  Backend Development  >  Symfony2实现在controller中获取url的方法_php实例

Symfony2实现在controller中获取url的方法_php实例

WBOY
WBOYOriginal
2016-06-07 17:08:39719browse

本文实例讲述了Symfony2实现在controller中获取url的方法。分享给大家供大家参考,具体如下:

// 假设当前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');

希望本文所述对大家基于Symfony框架的PHP程序设计有所帮助。

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