cakephp和呈现pdf

cakephp和呈现pdf,cakephp,pdf,plugins,Cakephp,Pdf,Plugins,大家好,我正在尝试为我的站点安装此插件。我目前正在运行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('

大家好,我正在尝试为我的站点安装此插件。我目前正在运行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>

查看发票
发件人:
接收人:
发票ID:
发票日期:
到期日:
地位:
行动:

项目名称 描述 单价 量 $
字段名 输入值 :

下面是我的app/config/bootstrap.php中的代码

<?php CakePlugin::load('DebugKit');
    CakePlugin::load('CakePdf', array('bootstrap' => true, 'routes' => true));
     CakePlugin::loadAll();

第一季度的答案
检查插件所需的路由配置。我以前没有使用过CakePdf插件,但听上去,它需要在“a”路由文件中包含以下内容:

Router::parseExtensions('pdf');
可以找到更多信息

第二季度的答案 您是否必须配置CakePdf插件才能知道您在本地安装的引擎在哪里?

回答问题1 检查插件所需的路由配置。我以前没有使用过CakePdf插件,但听上去,它需要在“a”路由文件中包含以下内容:

Router::parseExtensions('pdf');
可以找到更多信息

第二季度的答案
您是否必须配置CakePdf插件才能知道引擎的本地安装位置?

忽略我对问题1的回答,显然您必须确保
路由器::mapResources(数组([ControllerName])
存在于路由器配置中,其中[ControllerName]是处理PDF文件请求的控制器的名称。为了扩展我对第二个问题的回答,Github上插件的自述文件声明“binary”选项可用于设置WkHtmlToPdfEngine库的路径。我想您必须根据引擎的项目站点自己编译引擎。忽略我对问题1的回答,显然您必须确保
路由器::mapResources(数组([ControllerName])
存在于路由器配置中,其中[ControllerName]是处理PDF文件请求的控制器的名称。为了扩展我对第二个问题的回答,Github上插件的自述文件声明“binary”选项可用于设置WkHtmlToPdfEngine库的路径。我想您必须根据引擎的项目站点自己编译引擎。