我怎样才能得到这个基本网址
http://localhost/Symfony/web/app_dev.php/
或者
http://localhost/Symfony/web/app.php/
或者
http://localhost/Symfony/web/
(基本网址)
在 symfony2 配置文件中?在 symfony 网站上找不到。
$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;
嗯...检查这个:
$base = $this->getRequest()->getSchemeAndHttpHost();
或者最旧的版本(我不记得什么时候改变了):
$request = $this->getRequest();
$scheme = $request->getScheme();
$host = $request->getHttpHost();
$base = sprintf('%s://%s', $scheme, $host);