我正在尝试使用 DOMPdf 生成 PDF,其中我需要一个 volt 模板的 HTML。伏特模板是动态生成的。那么如何在我的控制器中获取 volt 模板 html 作为变量。
MyController 动作:
public function printEvaluationQuizResultAction() {
// I WANT TO GET HTML FROM a TEMPLATE in $html variable
//$html = $this->request->getPost('html');
// instantiate and use the dompdf class
$dompdf = new Dompdf();
$dompdf->loadHtml($html);
// (Optional) Setup the paper size and orientation
$dompdf->setPaper('A4', 'landscape');
// Render the HTML as PDF
$dompdf->render();
// Output the generated PDF to Browser
$dompdf->stream();
}
模板:
<div id="print_result" style="display:none">
<div class="row">
<!-- Start of Symptoms Card/Table/Section -->
<div class="col-md-6">
<div class="card">
<div class="card-header">
<div class="text-center"><span class="section-heading-text">SYMPTOMS</span></div>
</div>
<?php if($quizDataArray['symptoms']): ?>
{% for key, symptom in quizDataArray['symptoms'] %}
<div class="col-md-12 card-box">
<div class="card-body">
<h5 class="card-title">{{ symptom['title'] }}</h5>
<?php if (isset($symptom['results'])): ?>
<h6 class="card-subtitle mb-2 text-muted">
{% for key, result in symptom['results'] %}
<?php $causeId = key($result); ?>
{{ resultKeyArray[key] }} <?php if($causeId) { ?> {{ result[causeId] }} <?php } ?>
{% endfor %}
</h6>
<?php endif;?>
</div>
</div>
{% endfor %}
<?php endif; ?>
<div class="text-center"><span class="section-heading-text">DR. RECOMMENDED PRODUCTS</span></div>
<?php if($thingsToTry): ?>
<?php foreach ($thingsToTry as $remedy): ?>
<div class="col-md-12 card-box">
<div class="card-body">
<!-- Todo: To print image here -->
<div class="col-md-8">
<div class="info-box">
<h5><?php echo $remedy['title'] ?></h5>
<p>
<?php echo $remedy['description'] ?>
</p>
</div>
</div>
</div>
<div class="clear"></div>
</div>
<?php endforeach; ?>
<?php endif; ?>
<div class="text-center"><span class="section-heading-text">Health Food Store Recommendations</span></div>
<?php if($thingsToTry): ?>
{% for key, remedy in thingsToTry %}
<div class="remedy-box">
<h5><strong>*{{ remedy['title'] }}</strong></h5>
</div>
{% endfor %}
<?php endif; ?>
</div>
</div><!-- End of Symptoms Card/Table/Section -->
</div>
如果需要任何解释,我很乐意添加更多细节,请告诉我。
谢谢