>  기사  >  백엔드 개발  >  Symfony2实现在controller中获取url的方法_php实例

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

WBOY
WBOY원래의
2016-06-07 17:08:39719검색

本文实例讲述了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으로 문의하세요.