0

我怎样才能得到这个基本网址

http://localhost/Symfony/web/app_dev.php/

或者

http://localhost/Symfony/web/app.php/

或者

http://localhost/Symfony/web/

(基本网址)

在 symfony2 配置文件中?在 symfony 网站上找不到。

4

2 回答 2

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; 
于 2017-12-14T21:22:40.627 回答
-1

嗯...检查这个:

$base = $this->getRequest()->getSchemeAndHttpHost();

或者最旧的版本(我不记得什么时候改变了):

$request = $this->getRequest();
$scheme = $request->getScheme();
$host = $request->getHttpHost();

$base = sprintf('%s://%s', $scheme, $host);
于 2013-03-20T14:00:56.013 回答