这是我的 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));
}
问:我怎样才能在那里添加数据?比如 $data['name'] = "name";
问题 2:如何将数据放入我的 pdf 生成器?我怎么调用它
最佳答案
view()
方法接受三个参数。您可以将数据作为第二个参数传递。通过将第三个参数设置为 true,您可以将 View 作为字符串加载以传递给您的 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));
}
对于上面的示例,您可以使用以下方式访问 View 中的数据:
<?php echo $name; ?>
关于php - 如何将数据从 Controller 传递到 dompdf?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19087338/