How can I pass data to dompdf from controller?

不羁岁月 提交于 2019-12-10 18:17:34

问题


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


回答1:


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; ?>


来源:https://stackoverflow.com/questions/19087338/how-can-i-pass-data-to-dompdf-from-controller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!