《PHP實戰:Symfony2實現在controller中獲取url的方法》要點:
本文介紹了PHP實戰:Symfony2實現在controller中獲取url的方法,希望對您有用。如果有疑問,可以聯系我們。
PHP實例本文實例講述了Symfony2實現在controller中獲取url的辦法.分享給大家供大家參考,具體如下:
PHP實例
// 假設當前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');
PHP實例希望本文所述對大家基于Symfony框架的PHP程序設計有所贊助.
歡迎參與《PHP實戰:Symfony2實現在controller中獲取url的方法》討論,分享您的想法,維易PHP學院為您提供專業教程。
轉載請注明本頁網址:
http://www.snjht.com/jiaocheng/7313.html