首页 > 解决方案 > 特定站点的drupal 8路径

问题描述

我在 drupal 8 站点上使用 dompdf。我需要获取要放入其中的图像的绝对 URL。

在生成我的pdf的控制器的方法中,我能够恢复路径:

$path = PublicStream::basePath();
// $path returns : sites/default/files 
$getpath = file_create_url($path); 
// $getpath returns : http://localhost/drupal/sites/default/files

事实上,我不使用默认文件夹,而是将所有内容存储在特定站点中。我怎样才能检索“站点/我的站点/文件”呢?

标签: drupaldrupal-8

解决方案


不是很优雅但有效:

$host = \Drupal::request()->getSchemeAndHttpHost();
$host .= "/sites/mysite/files";

推荐阅读