문제

I have been searching for an easy way to get the ServerName of the machine where Symfony runs in Symfony (so that my app adapts when it is used on a host with a different ServerName), but I couldn't find one. I created a variable in app.yml and I fetch it, but I still wonder if there is no easier way to do this. How are you doing this? I'm using Symfony 1.2 and 1.4 on different projects.

도움이 되었습니까?

해결책

I think I found something :

$this->getRequest()->getHost()

This seems to work... it will work only it there is a request of course, so it is not universal.

다른 팁

Not very nice, but I use $_SERVER["SERVER_NAME"] in my front controller file, and use that to determine the environment I'm activating:

$env = "prod";
if (preg_match("/qahost\.tld$/", $_SERVER["SERVER_NAME"]))
{
  $env = "qa";
}
$configuration = ProjectConfiguration::getApplicationConfiguration('frontend', $env, false);
sfContext::createInstance($configuration)->dispatch();

I'd be interested to see the proper approach :-)

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top