我如何获得此基本网址
http://localhost/Symfony/web/app_dev.php/
OR
http://localhost/Symfony/web/app.php/
或
http://localhost/Symfony/web/
(基本网址)
在symfony2配置文件中?无法在symfony网站上找到。
答案 0 :(得分:0)
$protocol = stripos($_SERVER['SERVER_PROTOCOL'],'https') === true ? 'https://' : 'http://';
$hostName = $request->server->get('HTTP_HOST');
$baseDirectory = "";
if(!empty($this->container->get('router')->getContext()->getBaseUrl())){
$baseDirectory = str_replace('app_dev.php', '', $this->container->get('router')->getContext()->getBaseUrl());
}
$rootUrl = $protocol.$hostName.$baseDirectory;
答案 1 :(得分:-1)
$base = $this->getRequest()->getSchemeAndHttpHost();
或在最旧的版本中(我不记得何时更改):
$request = $this->getRequest();
$scheme = $request->getScheme();
$host = $request->getHttpHost();
$base = sprintf('%s://%s', $scheme, $host);