ホームページ  >  記事  >  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 までご連絡ください。