我需要Drupal 8域访问模块中的domain_get_domain(),但是我找不到它。
我需要找到当前请求的域。
发布于 2018-10-05 22:37:12
最后得出了以下结论..。
$domainNegotiator = \Drupal::service('domain.negotiator');
$current = $domainNegotiator->negotiateActiveHostname();DomainNegotiator服务上还有其他我认为应该工作的方法,特别是getActiveDomain()和getActiveId(),但是它们并没有像我想的那样返回我实际使用的域。
对我来说还是有点困惑,但我成功了。
编辑:@berramou‘下面的S回答也有帮助。最初,我在寻找域对象(来自域访问模块),但结果显示主机已经足够匹配我的实体上的域引用了。
发布于 2018-10-05 22:35:00
在drupal 8中,有\Drupal::request()来获取请求信息。
例如,如果您的url类似于https://example.com
如果您只想要域名example.com
$domain = \Drupal::request()->getHost();如果要使用架构http or https https://example.com的域名,请使用以下命令:
$domain_with_schema = \Drupal::request()->getSchemeAndHttpHost();https://drupal.stackexchange.com/questions/270473
复制相似问题