![](/img/trans.png)
[英]MPDF Can't Read My PHP Variable/Script in View Code Igniter
[英]MPDF Failed to Render HTML in Code Igniter
我正在使用Code Igniter v 2.2和最新的MPDF開發簡單的應用程序,以將視圖轉換為PDF。 我已經按此鏈接獲得了教程, 將CI結合使用MPDF
我無法獲取PDF輸出。 :d
我以為WriteHTML()
函數無法呈現我的視圖。 這是我的代碼
$this->load->library('m_pdf');
$pdf = $this->m_pdf->load();
$html = $this->load->view('cetak', true);
$pdf->WriteHTML($html);
但是,當我像這樣將$ html變量更改為HTML標記時,它可以工作。
$html = " <!DOCTYPE html>
<html lang='en'>
<head>
<meta charset='utf-8'>
<meta http-equiv='X-UA-Compatible' content='IE edge'>
<meta name='viewport' content='width = device-width, initial-scale = 1'>
<!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
<meta name='description' content=''>
<meta name='author' content=''>
<link rel='icon' href='../../favicon.ico'>
<title>Home</title>
<!-- Bootstrap core CSS -->
<link href='http://127.0.0.1:666/ticketing/assets/css/paper_bootstrap.css' rel='stylesheet'>
<!-- Custom styles for this template -->
<link href='http://127.0.0.1:666/ticketing/assets/css/jumbotron-narrow.css' rel='stylesheet'>
</head>
<body>
<div class='container'>
<div class='header clearfix'>
<nav>
<ul class='nav nav-pills pull-right'>
<li role='presentation' class='active'><a href='#'>Home</a></li>
<li role='presentation'><a href='#'>Logout</a></li>
</ul>
</nav>
<h3 class='text-muted'>King Jim Indonesia</h3>
</div>
<!-- Columns start at 50% wide on mobile and bump up to 33.3% wide on desktop -->
<strong>Execute time : {elapsed_time} seconds</strong>
<a href='http://127.0.0.1:666/ticketing/index.php/welcome/cetak/2015/3'>Cetak</a>
<div class='row'>
<div class='col-md-4' style='border: 1px solid #e1e1e8; margin-bottom: 5px;'>
<table style='width: 100%; color: #0060f1'>
<tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>PT. KING JIM INDONESIA</strong></td></tr>
<tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>KUPON MAKAN</strong></td></tr>
<tr><td colspan='2' class='text-center' style='text-decoration: underline;'><strong>juni, 2015</strong></td></tr>
<tr>
<td class='text-left'><h2 style='margin-top: 0px; margin-bottom: 0px; color: #0060f1'>12</h2></td>
<td class='text-right'><h3 style='margin-top: 0px; margin-bottom: 0px; color: #144691'>212</h3></td>
</tr>
<tr><td colspan='2' style='font-size: 13px; font-style: italic'>1. Kupon ini hanya berlaku sesuai bulan & tanggal</td></tr>
<tr><td colspan='2' style='font-size: 13px; font-style: italic'>2. Tidak dapat diuangkan</td></tr>
</table>
</div>
<?php
}
?>
</div>
<?php
}
?>
</div> <!-- /container -->
</body>
</html>";
誰能告訴我我的錯誤在哪里。 問候。
您錯過了從視圖中獲取字符串的機會。 這是因為您將true
傳遞給第二個參數。 第二個參數應該為空或為null
,第三個參數需要設置為布爾值以獲取字符串:
$html = $this->load->view('cetak', '', true);
嘗試這種方式。
您的HTML用雙引號引起來。 嘗試使用單引號。 您所有的單引號都需要轉義或更改為雙引號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.