我如何传递数据到dompdf从控制器? [英] How can I pass data to dompdf from controller?

查看:90
本文介绍了我如何传递数据到dompdf从控制器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的控制器:

  function dompdf(){
$ this-> load-> view('contracts / equipment_pdf');
$ html = $ this-> output-> get_output();
$ this-> load-> library('dompdf_gen');
$ this-> dompdf-> load_html($ html);
$ this-> dompdf-> render();
$ this-> dompdf-> stream(test.pdf,array(Attachment=> 0));
}

问:我如何添加数据?像$ data ['name'] =name;



Q2:如何将数据放入我的pdf生成器?我将如何调用它 $ $ view()方法接受三个参数。您可以将您的数据作为第二个参数传递。通过将第三个参数设置为true,您可以将视图作为字符串加载到您的pdf类中。

  function dompdf(){
$ data ['name'] =name;
$ html = $ this-> load-> view('contracts / equipment_pdf',$ data,true);
$ this-> load-> library('dompdf_gen');
$ this-> dompdf-> load_html($ html);
$ this-> dompdf-> render();
$ this-> dompdf-> stream(test.pdf,array(Attachment=> 0));
}

对于上述示例,您可以使用以下方式访问视图中的数据: / p>

 <?php echo $ name; > 


this is my controller:

function dompdf(){
            $this->load->view('contracts/equipment_pdf');
            $html = $this->output->get_output();
            $this->load->library('dompdf_gen');
            $this->dompdf->load_html($html);
            $this->dompdf->render();
            $this->dompdf->stream("test.pdf", array("Attachment" => 0));
    }

Q: How can i add data there? like $data['name'] = "name";

Q2: How can i put the data in my pdf generator? how will i call it

解决方案

The view() method accepts three parameters. You can pass your data as the second parameter. By setting the third parameter to true, you are able to load the view as a string to pass to your pdf class.

    function dompdf(){
       $data['name'] = "name";
       $html = $this->load->view('contracts/equipment_pdf', $data, true);
       $this->load->library('dompdf_gen');
       $this->dompdf->load_html($html);
       $this->dompdf->render();
       $this->dompdf->stream("test.pdf", array("Attachment" => 0));
   }

For the above example, you can access the data in your view using:

<?php echo $name; ?>

这篇关于我如何传递数据到dompdf从控制器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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