是否有任何 Zend Helper 可以制作带有表格的 PDF 文档。我需要传递我的查询结果,助手将返回一个 PDF 文档,其中包含表格中的数据。就像下面的 Csv Helper 一样。
我在这里所做的是我将给定的课程放入
Zend/Controller/Action/Helper
而不是在我的行动中我这样做
public function getcsvAction() {
$this->_helper->layout()->disableLayout();
$this->_helper->viewRenderer->setNeverRender();
try{
$clModel = new Application_Model_DbTable_Mytable();
$select = $clModel->clCSV());
$this->_helper->Csv($select, "genertadfile name");
}catch(Exception $e){
echo 'Oops! Something went wrong.';
}
exit;
}
这堂课
<?php
// Zend_Controller_Action_Helper_Csv
class Zend_Controller_Action_Helper_Csv extends Zend_Controller_Action_Helper_Abstract{
public function direct($aryData = array(), $strName = "csv", $bolCols = true){
$this->printExcel($aryData, $strName, $bolCols);
}
public function printExcel($aryData = array(), $strName = "csv", $bolCols = true){
if (!is_array($aryData) || empty($aryData)){ exit(1); }
// header
header('Content-Description: File Transfer');
header('Content-Type: text/csv; charset=utf-8');
header("Content-Disposition: attachment; filename=" . $strName . "-export.csv");
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-control: private, must-revalidate');
header("Pragma: public");
if ($bolCols){
$aryCols = array_keys($aryData[0]);
array_unshift($aryData, $aryCols);
}
ob_start();
$fp = fopen("php://output", "w");
if (is_resource($fp)){
foreach ($aryData as $aryLine) {
fputcsv($fp, $aryLine, ',', '"');
}
$strContent = ob_get_clean();
$strContent = preg_replace('/^ID/', 'id', $strContent);
$strContent = utf8_decode($strContent);
$intLength = mb_strlen($strContent, 'utf-8');
header('Content-Length: ' . $intLength);
echo $strContent;
exit(0);
}
ob_end_clean();
exit(1);
}
}
?>