【发布时间】:2011-05-30 19:39:26
【问题描述】:
我在我的应用程序中使用 Doctrine 1.2.3,我正在尝试使用 zend_pdf_table 组件根据以下教程 http://devzone.zend.com/article/12492-Creating-PDF-Documents-with-Zend-Framework 创建 PDF 报告。
编辑文档已创建,但我只能让第一条记录出现在报告中,尽管尝试添加我自己的样式,但仍然出现样式错误。
我可能会离开这个,因为我的项目时间不多了,我会考虑从头开始创建自己的 PDF。
[error] [client 127.0.0.1] PHP Notice: Trying to get property of non-object in C:\\WebDocs\\xx\\library\\Zend\\Pdf\\Style.php on line 211
我修改后的代码如下
// report to print todays appointments
public function todaysgroomingappointmentsAction()
{
try{
$t=date('y-m-d');
$q = Doctrine_Query::create()
->select('CONCAT(g.gapmtSTime, g.gapmtETime) AS Time, CONCAT(c.firstname, c.lastname) AS Client, p.name AS Pet, r.groomprocedure AS Procedure, u.name AS Groomer')
->from('PetManager_Model_Groomappointments g')
->leftJoin('g.PetManager_Model_Clients c')
->leftJoin('g.PetManager_Model_Pets p')
->leftJoin('g.PetManager_Model_Users u')
->leftJoin('g.PetManager_Model_Groomservices s')
->leftJoin('s.PetManager_Model_Groomprocedures r')
->where('g.gapmtStatus = 1 AND g.gapmtDate = ?',$t);
$result = $q->fetchArray();
require_once 'Zend/Pdf.php';;
require_once 'My/Pdf.php';
require_once 'My/Pdf/Document.php';
require_once 'My/Pdf/Page.php';
require_once 'My/Pdf/Table.php';
require_once 'My/Pdf/Table/Row.php';
require_once 'My/Pdf/Table/Cell.php';
require_once 'My/Pdf/Table/Column.php';
require_once 'My/Pdf/Table/HeaderRow.php';
// create PDF
$pdf = new My_Pdf_Document('todaysappointments.pdf', 'D:/');
// create page
$page = $pdf->createPage();
// define font resource
$font = Zend_Pdf_Font::fontWithName(Zend_Pdf_Font::FONT_HELVETICA);
// set font
$page->setFont($font, 24);
// create table
$table = new My_Pdf_Table(4);
// iterate over record set
// set up table content
foreach ($result as $record) {
$row = new My_Pdf_Table_Row();
$cols = array();
foreach ($record as $k => $v) {
$col = new My_Pdf_Table_Column();
$col->setText($v);
$cols[] = $col;
}
$row->setColumns($cols);
$row->setFont($font, 14);
$row->setBorder(My_Pdf::TOP, new Zend_Pdf_Style());
$row->setBorder(My_Pdf::BOTTOM, new Zend_Pdf_Style());
$row->setBorder(My_Pdf::LEFT, new Zend_Pdf_Style());
$row->setCellPaddings(array(10,10,10,10));
$table->addRow($row);
}
// add table to page
$page->addTable($table, 0, 0);
// add page to document
$pdf->addPage($page);
// save as file
$pdf->save('todaysappointments.pdf');
echo 'SUCCESS: Document saved!';
} catch (Zend_Pdf_Exception $e) {
die ('PDF error: ' . $e->getMessage());
} catch (Exception $e) {
die ('Application error: ' . $e->getMessage());
}
}
谁能告诉我为什么会出现这个错误以及如何解决它。
非常感谢。
【问题讨论】:
-
Zend_Pdf_Styleline #211 是return $this->_lineWidth->value;所以我猜这是$_lineWidth属性的问题 -
只是一个旁注:这里有点autloading 将有助于收紧一点。
-
@Phil lineWidth 实际上是由包本身提供的 我试图在我的代码中输入它,但我仍然收到错误。