如何创建链接以下载symfony2中生成的文档? [英] How to create a link to download generated documents in symfony2?

查看:84
本文介绍了如何创建链接以下载symfony2中生成的文档?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

文档由系统创建,并保存到/web/downloads文件夹中.我创建了一个显示链接的视图,如果用户单击链接,该链接将允许用户下载文件. (标准的点击下载功能)

Documents are created by the system and saved to the folder /web/downloads. I have created a view to display links which will allow a user to download the files, should the user click the links. (standard click to download feature)

我是Symfony2的新手,并且了解了整个路由/控制器的概念,但是如何在仍坚持MVC的同时创建指向此类文件的链接?是否需要使用控制器来设置路由,还是树枝具有允许它的功能等?

I am new to Symfony2 and am getting around the whole routing/controller concept, but how would one create a link to such files while still adhering to the MVC? Does one need to set up routing with a controller or does twig have features which allow it etc.

PS: 我已经阅读了诸如如何在Symfony2中创建下载链接的问题?但我不知道他们是否在路由中做了某件事或只是添加了链接等.

PS: I have read questions such as How to create a download link in Symfony2? but i do not get if they did something in the routing or just added links etc.

谢谢

推荐答案

让我们做一个样本.

假设您的项目位于/www/中,因此/www/web/是symfony2应用程序的文档根目录.现在,您尝试通过/www/web/通过 http://server/访问的所有内容都将显示.

Say your project lives in /www/, so /www/web/ is the document root of your symfony2 application. Now everything you try to access that is in /www/web/ over http://server/ will show up.

/www/web/downloads/file.zip默认情况下.

/www/web/downloads/file.zip would be reachable at http://server/downloads/file.zip by default.

这篇关于如何创建链接以下载symfony2中生成的文档?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆