大家好,我正在尝试为我的网站安装此插件。我目前正在运行 cake 2.1 并希望单击一个链接并将发票呈现为 pdf 格式,以便用户可以使用它做任何他们想做的事情。目前,如果我转到http://localhost/pra/invoices/view/1.pdf
它会加载一个与如果我转到相同的 html 页面http://localhost/pra/invoices/view/pdf/1
这是我在发票控制器中查看操作的代码
public function view($id = null) {
$this->set('title_for_layout', 'Invoices');
$this->set('stylesheet_used', 'homestyle');
$this->set('image_used', 'eBOXLogoHome.png');
$this->layout='adminpdf';
$this->pdfConfig = array('engine' => 'CakePdf.WkHtmlToPdf');
$this->Invoice->id = $id;
if (!$this->Invoice->exists()) {
throw new NotFoundException(__('Invalid invoice'));
}
$this->pdfConfig = array(
'orientation' => 'potrait',
'filename' => 'Invoice_' . $id
);
$this->set('invoice', $this->Invoice->read(null, $id));
//Retrieve Account Id of current User
$accountid=$this->Auth->user('account_id');
//Find all Invoices where $conditions are satisfied
$invoicedetails=$this->Invoice->find('first', array(
'conditions' => array('Invoice.id'=>$id)));
//prints fieldsInvoice details, including invoice and field information
$invoices=$this->FieldsInvoice->find('all',array(
'conditions'=>array(
'invoice_id'=>$id)));
$itemInvoice=$this->InvoicesItem->find('all',array('conditions'=>array('invoice_id'=>$id)));
//Set variables
$this->set('invoicedetails', $invoicedetails);
$this->set('invoice', $invoices);
$this->set('accountid', $accountid);
$this->set('itemInvoice', $itemInvoice);
}
这是该操作的视图文件
<div id = "content">
<h2>View Invoice</h2>
<table id="data">
<?php
if($invoicedetails['Invoice']['scheduled']==1)
{
$status = 'Scheduled';
$fcol = 'Black';
$bgcol = '#EBD8E8';
$pay = NULL;
$dispute = NULL;
}
else if($invoicedetails['Invoice']['paid']==1)
{
$status = 'Paid';
$fcol = 'Black';
$bgcol = '#B9FAEA';
$pay = NULL;
$dispute = NULL;
}
else if($invoicedetails['Invoice']['sender_id']==$accountid)
{
$status = 'Sent';
$fcol = 'Black';
$bgcol = '#F8FAC0';
$pay = NULL;
$dispute = NULL;
}
else if($invoicedetails['Invoice']['receiver_id']==$accountid)
{
$status = 'Received';
$fcol = 'Black';
$bgcol = '#FAB9B9';
$pay = $this->Html->link('Pay', array('controller' => 'Invoices','action'=>'pay_admin',$invoicedetails['Invoice']['id'] )) ;
$dispute = $this->Html->link('Dispute', array('controller' => 'Disputes','action'=>'add_admin',$invoicedetails['Invoice']['id'] ));
}
?>
<tr>
<th>Sender: </th>
<td><?php echo $invoicedetails['SenderAccount']['account_name'];?> </td>
</tr>
<tr>
<th>Receiver: </th>
<td><?php echo $invoicedetails['ReceiverAccount']['account_name'];?> </td>
</tr>
<tr>
<th>Invoice ID: </th>
<td><?php echo $invoicedetails['Invoice']['id'];?> </td>
</tr>
<tr>
<th>Invoice Date: </th>
<td><?php echo date('d.m.Y', strtotime($invoicedetails['Invoice']['created'])); ?></td>
</tr>
<tr>
<th>Due Date: </th>
<td><?php echo date('d.m.Y', strtotime($invoicedetails['Invoice']['expiry_date'])); ?></td>
</tr>
<tr>
<th>Status: </th>
<td bgcolor='<?php echo $bgcol ?>'><?php echo $status ;?> </td>
</tr>
<tr>
<th>Actions: </th>
<td><?php echo $pay ?> <?php echo $dispute ?></td>
</tr>
</table>
<br>
<table id="data">
<tr>
<th>Item Name</th>
<th>Description</th>
<th>Price Per Unit</th>
<th>Quantity</th>
</tr>
<?php foreach($itemInvoice as $itemInvoices):?>
<tr>
<td><?php echo $itemInvoices['Item']['name']; ?></td>
<td><?php echo $itemInvoices['Item']['description']; ?></td>
<td>$<?php echo number_format($itemInvoices['Item']['price'], 2, '.', ','); ?></td>
<td><?php echo $itemInvoices['InvoicesItem']['quantity']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<br>
<table id="data">
<tr>
<th>Field Name</th>
<th>Entered Value</th>
</tr>
<?php foreach($invoice as $invoices):?>
<tr>
<td><?php echo $invoices['Field']['name']; ?> :</td>
<td><?php echo $invoices['FieldsInvoice']['entered_value']; ?></td>
</tr>
<?php endforeach; ?>
</table>
<br><br>
这是我的 app/config/bootstrap.php 中的代码
<?php CakePlugin::load('DebugKit');
CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
CakePlugin::loadAll();
这是 layouts/pdf/adminpdf.ctp 中的布局文件
<?php echo $this->Html->docType('xhtml-trans'); ?>
<html>
<div id = "header" style="background-image:url(<?php echo $this->webroot; ?>img/BannerGradient.jpg);">
<head>
<title> <?php echo $title_for_layout; ?></title>
<?php echo $this->Html->css($stylesheet_used); ?>
<?php echo $this->Html->script(array('jquery','modal.popup')); ?>
<div id='logo'> <center>
<?php echo $this->Html->image($image_used, array(
"alt" => "eBox",
'url' => array('controller' => 'eboxs', 'action' => 'home_admin'))) ?>
</center></div>
<div id="welcome">
<?php if($logged_in): ?>
Logged in as <text6><?php echo $current_user['username']; ?></text6> <?php echo $this->Html->link('My Profile', array('controller'=>'Accounts', 'action'=>'index')); ?> | <?php echo $this->Html->link('Logout', array('controller'=>'users', 'action'=>'logout')); ?>
<?php else: ?>
<?php echo $this->Html->link('Login', array('controller'=>'users', 'action'=>'login')); ?>
<?php endif; ?>
</div>
</head>
</div>
<body>
<?php echo $this->Session->flash(); ?>
<?php echo $this->fetch('content'); ?>
</body>
</html>
我在这个目录中也有 WkHtmlToPdf 引擎C:\Program Files (x86)\wkhtmltopdf
我有 2 个问题
1)我在views/invoices/views.ctp和views/invoices/pdf/views.ctp中有两个视图,但似乎从invoices/views.ctp中读取了一个,对吗?我的布局文件也发生了同样的事情。
2) 我需要将 cake 引导到我的 WkHtmlToPdf 引擎还是应该找到它?