当我将图像存储在我的包中时,dir结构使用Assetic很容易显示图像:
{% image '@AcmeFooBundle/Resources/public/images/example.jpg'
filter='jpegoptim' output='/images/example.jpg'
%}
<img src="{{ asset_url }}" alt="Example"/>
{% endimage %}
但如何为上传的图片使用资产?在我的getWebPath下面返回相对于web dir的路径,例如:“/ uploads / images / images.jpg”。也许这个解决方案没问题,没有必要使用资产?我认为将它用于像jpegoptim这样的过滤可能很有用
<img src="{{app.request.basepath}}/{{ entity.getWebPath }}">
答案 0 :(得分:5)
<img src="{{ app.request.scheme ~ '://' ~ app.request.host ~ '/' ~ entity.getWebPath }}" />
答案 1 :(得分:0)
您可以使用getUploadRootDir(),getAbsolutePath()等将它们存储在automaticcaly生成的web direectory'uploads / files /'上,然后使用
调用它们
src =“{{asset('uploads / files /'~entity.path)}}”