我用谷歌搜索了它,但也许我的搜索关键字没用,那么如何在 Controller 中获取 URL 协议(protocol)?是 http://还是 https://
http://whatever.com/app_dev.php/welcome
//I need to echo http:// protocol here
echo $request->getHost(); //echos whatever.com
echo $request->getBaseUrl(); //echos app_dev.php/
最佳答案
您可以在 Controller 中使用它:
$scheme = $this->getRequest()->getScheme();
否则,这里有一段代码可以让你知道服务器返回的所有值:
foreach ($_SERVER as $key => $value) {
echo $key.' => '.$value.'<br>';
}
关于symfony - 从 Controller 中的 URL 获取协议(protocol),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24585521/