首页  >  文章  >  php教程  >  Symfony2实现在controller中获取url的方法

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

WBOY
WBOY原创
2016-06-06 19:32:461294浏览

本文实例讲述了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();// 1

本文实例讲述了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程序设计有所帮助。

声明:
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn