我在加载CSS和图像资源时收到Authentication Required错误.
错误示例:
Warning: Failed to load http://reporter.dev:8888/css/fc84af4_part_1_bootstrap-editable_2.css (ignore)
Run Code Online (Sandbox Code Playgroud)
我使用KNP Snappy包如下:
$html = $this->renderView(
'InterlatedReporter:Allocation:casual_calendar_pdf.html.twig',
array(
'casualCalendar' => $casualCalendar,
)
);
$filename = "export-casual-calendar-" . date("Ymd") . '.pdf';
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
array(
'Content-Type' => 'application/pdf',
'Content-Disposition' => 'attachment; filename="' . $filename . '"'
)
);
Run Code Online (Sandbox Code Playgroud)
树枝模板已添加绝对路径,如下所示.URL似乎使用file://
{{ app.request.getSchemeAndHttpHost() ~ asset('css/sortable-theme-bootstrap.css') }}
Run Code Online (Sandbox Code Playgroud)
我尝试过使用安全性,开发防火墙已经到位:
dev:
pattern: ^/(_(profiler|wdt)|css|images|js)/
security: false
Run Code Online (Sandbox Code Playgroud)
这是第一条规则.
我们按照SensioFrameworkExtraBundle使用控制器注释.
我也尝试按照Symfony 2 kpn传递会话snappy生成pdf,输出符合安全区域
如何加载资源?
我发现了一个问题.file://是关键.
传递给模板的基目录:
$html = $this->renderView(
'InterlatedReporter.html.twig',
array(
'casualCalendar' => $casualCalendar,
'base_dir' => $this->get('kernel')->getRootDir() . '/../web' . $request->getBasePath()
)
);
Run Code Online (Sandbox Code Playgroud)
并提供资产的完整路径:
<link rel="stylesheet" href="{{ base_dir ~ asset('css/sortable-theme-bootstrap.css') }}">
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
4745 次 |
最近记录: |