In my application I need get domain name. I get it from request by means of next command :
Yii::$app->getRequest()->serverName
But when I run functional tests I get Exeption, because the created crawler doesn't have variable $_SERVER['SERVER_NAME']. This is content of $_SERVER :
{
'HTTP_HOST' => string(9) "localhost"
'HTTP_USER_AGENT' => string(19) "Symfony2 BrowserKit"
'HTTPS' => bool(true)
'REQUEST_URI' => string(15) "/index-test.php"
'REQUEST_METHOD' => string(3) "GET"
}
Many parameters of class Request have check of isset :
https://github.com/yiisoft/yii2/blob/master/framework/web/Request.php#L842
https://github.com/yiisoft/yii2/blob/master/framework/web/Request.php#L851
https://github.com/yiisoft/yii2/blob/master/framework/web/Request.php#L869
But getServerName doesn't have it.
Sorry for my bad English )
Php checks server_name variable for existing, I suppose.
?
Зачем делать проверку поля, если оно по умолчанию забивается самим php?
В первом посте написано же: https://github.com/yiisoft/yii2/issues/10451#issue-123325703
@samdark
is better Yii::$app->getRequest()->serverName or Yii::$app->request->serverName ?
@NabiKAZ doesn't matter.
Yii::$app->request->hostInfo
Most helpful comment
@NabiKAZ doesn't matter.