PHP(Zend) & Smarty - 生成 .doc 文件和 http 标头时出现问题
我在一个项目中使用 Zend Framework 和 Smarty 模板生成器,我对这项工作以及 ZF 和 Smarty 都是新手。不管怎样,在一个操作中,有一个用于生成 .doc 报告的可点击链接。单击后,它会使用 HtmlToDoc类通过这种方法:
$htmltodoc_instance -> createDoc($body ,
'filename.doc',
TRUE);
/* the last parameter TRUE means: download or save the file. it set the HTTP headers
'Content-type: application/octet-stream' and 'Content-Disposition: attachment;
filename="..."', forcing the browser to open a download dialog for filename.doc
之前已经通过
$this -> view -> obj_to_render = $obj_to_render.
在视图中放置了obj_to_render来渲染当前的action,而$obj_to_render一般是Smarty格式化的html代码模板引擎。 我不知道这是否是原因,但似乎这导致了问题:.doc 下载对话框的标题在某种程度上被视图渲染的下一个标题“覆盖”,因此 .doc 文件的输出不成功。我尝试在 createDoc() 方法调用之后放置 exit() ,但它确实有很大帮助。输出有所不同,但它仍然没有显示我需要的信息。有人知道如何划分这两个操作然后获得正确的文件输出吗? 谢谢!
i'm using the Zend Framework and Smarty Template generator on a project, i'm new to this work and also to ZF and Smarty. Anyway, on an action there's a clickable link for a .doc report generation. Once clicked, it generates a .doc file using HtmlToDoc class by this method:
$htmltodoc_instance -> createDoc($body ,
'filename.doc',
TRUE);
/* the last parameter TRUE means: download or save the file. it set the HTTP headers
'Content-type: application/octet-stream' and 'Content-Disposition: attachment;
filename="..."', forcing the browser to open a download dialog for filename.doc
before that, it has been renderd the current action by
$this -> view -> obj_to_render = $obj_to_render.
with obj_to_render placed in the view, while $obj_to_render is generally the formatted html code by Smarty template engine.
I don't know if it is the cause, but it seems that this cause the problem: the header of .doc download dialog is somehow 'overriden' by the next header of view's rendering, and so the .doc file's output is not succesful. i've tried to put an exit() after createDoc() method call, but it doens help much. output is diferent, but it still doesn't display the informations i need. Anybody know how to divide this two operations and then obtain the right file output?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
GDocs 可以很好地处理此文件。无法在 MS Word 上进行测试,我没有它:)
GDocs works fine with this file. cant test on MS Word, i dont have it :)