[英]Render a partial view with layout in Zend Framework 1.12
Similar questions have been asked before but unfortunately I am still not able to find a solution of my problem. 之前曾问过类似的问题,但不幸的是,我仍然无法找到解决问题的方法。
I want to render a view with its layout and store its response into a variable. 我想用其布局呈现一个视图,并将其响应存储到变量中。
I have an action called pdf as shown below. 我有一个名为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);
}
This is the pdf view for the above action. 这是上述操作的pdf视图。
<?php echo $this->render('templates/grid/print-grid.phtml'); ?>
And here's the pdf layout 这是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>
So far I have tried using render()
and partial()
methods but none of them worked. 到目前为止,我已经尝试使用
render()
和partial()
方法,但是它们都不起作用。
Is there a way using which I can get the out put of the pdf view along with its layout inside the pdfAction()
method? 有没有一种方法可以获取pdf视图及其在
pdfAction()
方法中的布局?
You need to use : 您需要使用:
$this->_helper->layout->setLayout('/path/to/your/pdf_layout_script');
in your pdfAction()
and after that you can use render()
or partial()
methods, the corrects layout should be out put 在
pdfAction()
,然后可以使用render()
或partial()
方法,应将正确的布局放出来
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.