【发布时间】:2020-01-10 16:48:05
【问题描述】:
我在我的 Symfony 4 项目中使用 VichUploaderBundle 包来上传附件。 上传效果很好,但我很烦显示这些附件。
我使用插件“ekko-lightbox”(或其他插件,如果你知道更好?),直接向用户显示附件而不离开页面,但我得到了很多奇怪的字符......。
这是我的代码(我使用控制器来检查用户是否有权下载文件):
/**
* @Route("/ticket/attachment/{id}", name="ticketing_attachments", methods="GET")
* @IsGranted("ROLE_USER")
*/
public function getTicketAttachment(TicketAttachment $ticketAttachment, DownloadHandler $downloadHandler, TicketManager $ticketManager): Response
{
if(!$ticketManager->hasPermissionViewTicket($ticketAttachment->getTicket(), $this->getUser())) {
throw new HttpException(404, 'La page que vous avez demandée n\'existe pas.', null, [], 1);
}
return $downloadHandler->downloadObject($ticketAttachment, $fileField = 'file', $objectClass = null, $fileName = null, $forceDownload = false);
}
树枝:
{% if ticket.attachments|length > 0 %}
<hr/>
{% for attachment in ticket.attachments %}
<span class="glyphicon glyphicon-paperclip"></span>
<a href="{{ path('ticketing_attachments', {id: attachment.id}) }}" data-toggle="lightbox">{{ attachment.name }}</a>
{% endfor %}
{% endif %}
当我直接转到路线“/ticket/attachment/{id}”时,会显示附件,但使用 ekko-lightbox 插件是我得到的(很多奇怪的字符 ��):
【问题讨论】:
标签: symfony symfony4 vichuploaderbundle