渲染视图而不在浏览器中加载 - cakephp [英] Render a View without loading in the browser - cakephp

查看:176
本文介绍了渲染视图而不在浏览器中加载 - cakephp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我使用的cakephp组件使用mPDF来生成PDF文件。组件工作很好,如果你在浏览器中加载操作和视图,但是当我想生成和保存的pdf驱动器,它似乎并没有踢,我假设是因为视图没有加载属性。



我使用的组件是: https:// github .com / segy / Mpdf



所以基本上我有一个名为mail_merge的函数,它使用提到的组件生成pdf,我需要调用mail_merge函数在同一控制器内的另一个功能生成pdf但没有在浏览器中加载。



感谢



更新:



如何将视图设置为变量,然后将其写入函数中的pdf。



添加:

  //呈现视图并设置为可变的写入HTML 
// ------------------ -------------------------------------------------- ------->
$ response = $ this-> render('mail_merge');
$ thebody = $ response-> body();
$ this-> Mpdf-> WriteHTML($ thebody);

不幸的是,我的PDF仍然不会生成,所以我猜这个问题是别的。

解决方案

尝试这种方式:

  $ Response = $ this-> render('mail_merge'); 
$ thebody = $ response-> body();
$ this-> Mpdf-> WriteHTML($ thebody);
$ this-> Mpdf-> Output('filename.pdf');


I am wondering if it is possible to render an action's view without loading in the browser?

I'm using a cakephp component that used mPDF to generate PDF files. The component works well if you load the action and view in a browser but when I want to generate and save the pdf to the drive it doesn't seem to kick in, I'm assuming it's because the view isn't loaded property.

The component I am using is: https://github.com/segy/Mpdf

So basically I have a function called mail_merge which generates a pdf using the mentioned component, I need to call the mail_merge function from another function within the same controller to generate the pdf but without loading in the browser.

Thanks

UPDATE:

I worked out how to set the view as a variable and then write it to the pdf in the function.

ADDED THIS:

// RENDER THE VIEW AND SET AS A VARIABLE TO WRITE THE HTML
// --------------------------------------------------------------------------->
$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);

Unfortunately my PDF still won't generate so I guess the issue is something else.

解决方案

Try this way:

$response = $this->render('mail_merge');
$thebody = $response->body();
$this->Mpdf->WriteHTML($thebody);
$this->Mpdf->Output('filename.pdf');

这篇关于渲染视图而不在浏览器中加载 - cakephp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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