2

以前也有人问过类似的问题,但不幸的是我仍然无法找到解决问题的方法。

我想用它的布局渲染一个视图并将它的响应存储到一个变量中。

我有一个名为 pdf 的操作,如下所示。

public function pdfAction(){
        $ids = $this->getParam('id');
        $entity = $this->getParam('entity');
        $referer = $this->getRequest()->getServer('HTTP_REFERER');
        if(empty($ids) || empty($entity)){
            $this->_helper->redirector->gotoUrlAndExit($referer);
        }
        $grid = $this->_exportModel->getExportGrid($ids, $entity);
        if(empty($grid->data[0])){
            $this->_helper->messenger->error('No user was found for the given id. Please pass the correct parameters and try again.');
            $this->_helper->redirector->gotoUrlAndExit($referer);
        }

        /* I would like to render the view here and get its response below. */
        $html = '';

        $pdf = new Om_PDF();
        $pdf->writeHtmlToPDF($html);
    } 

这是上述操作的 pdf 视图。

<?php echo $this->render('templates/grid/print-grid.phtml'); ?>

这是pdf布局

<?php echo $this->doctype(); ?>
<html moznomarginboxes mozdisallowselectionprint>
<link rel="stylesheet" type="text/css" href="//maxcdn.bootstrapcdn.com/bootstrap/3.1.0/css/bootstrap.min.css" media="all"/>
<style type="text/css">

    .container {
        margin: 0 auto;
        max-width: 1000px;
        text-align: center;
        margin-top: 30px;
    }

    @media print {
        @page {
            size: auto;
            margin: 15mm 10mm 15mm 10mm;
        }

        body {
            margin: 0px;
        }

        .page-break {
            display: block;
            page-break-before: always;
        }

        .print-view-table {
            float: left;
            width: 45% !important;
            margin-right: 5%;
        }

        .print-view-table tr th, .print-view-table tr td {
            width: 30%;
        }

        .print-view-table tr th {
            background-color: #e0e0e0 !important;
            border: 1px solid #ddd;
            -webkit-print-color-adjust: exact;
        }

    }
</style>
<head>
    <?php ?>
</head>
<body>
<div class="container">
    <div class="row">
        <?php echo $this->layout()->content; ?>
    </div>
</div>
</body>
</html>

到目前为止,我已经尝试过使用render()partial()方法,但它们都没有奏效。

有没有一种方法可以让我输出 pdf 视图及其在pdfAction()方法内的布局?

4

1 回答 1

0

您需要使用:

$this->_helper->layout->setLayout('/path/to/your/pdf_layout_script');

在你pdfAction()和之后你可以使用render()orpartial()方法,应该输出正确的布局

于 2016-06-20T07:52:18.520 回答