php - 如何将多个 View 加载到 mpdf

标签 php codeigniter mpdf

只是一个简短的问题。任何人都知道是否可以将多个 View 从 codeigniter 加载到 mpdf Controller 并将其转换为 pdf? 我的 Controller : `

<?php

class C_Pdf extends CI_Controller {

private $params = array();

  function __construct() {
    parent::__construct();
    $this->params['set_tag'] = array();
    $this->params['set_css'] = array();
    $this->params['set_js'] = array();
    $this->params['title_auto'] = true;
    $this->params['title'] = '';
  }
public function index(){

//this data will be passed on to the view
$data['the_content']='mPDF and CodeIgniter are cool!';
$data['other']="siema heniu cos przeszlo";
//load the view, pass the variable and do not show it but "save" the output into $html variable
 $this->load->view('common/default_header',$this->params);
$html=$this->load->view('reservation/complete', $data,true);  
$this->load->view('common/default_footer');
//this the the PDF filename that user will get to download

//load mPDF library
$this->load->library('m_pdf');
//actually, you can pass mPDF parameter on this load() function
$pdf = $this->m_pdf->load();
//generate the PDF!
$pdf->WriteHTML($html);
//offer it to user via browser download! (The PDF won't be saved on your server HDD)
$pdf->Output();

}

}?>

我想从其他 View 添加页脚和页眉。

最佳答案

只需将页眉和页脚模板预取到变量中,然后将它们解析后的字符串传递给主视图,如下所示:

$data['header'] = $this->load->view('common/default_header',$this->params, true);
$data['footer'] = $this->load->view('common/default_footer', true);
$html = $this->load->view('reservation/complete', $data, true); 

注意第三个参数true,这样您就可以在字符串中获取 View ,而不是将其发送到输出(最常见的是客户端浏览器)。

然后在您的主模板中,将 $header$footer 变量放在您需要的任何位置。

关于php - 如何将多个 View 加载到 mpdf,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31296487/

相关文章:

php - 修复 MAMP 中的 Laravel 编码

javascript - Symfony|Twig : update data after ajax call

php - 使用 PDO 从 PostgreSQL bytea 插入和检索图像

php - Codeigniter Session匹配IP

php - 在 php 中使用 mPDF 将 html 转换为 pdf 时出现对齐干扰

php - Adobe Reader 无法从使用 mPDF 生成的 PDF 中检索嵌入字体

php - 在 & 但不是 && 处拆分字符串

php - 如何在 CodeIgniter 的库中使用 session ?

php - Composer 下载mpdf时出现的问题

codeigniter - CodeIgniter不允许的关键字符