【问题标题】:External PHP file to dompdf外部 PHP 文件到 dompdf
【发布时间】:2018-04-17 09:25:48
【问题描述】:

我有以下 PHP 文件 course.php,我希望 dompdf 呈现该文件。但是,当我尝试加载外部文件时,它会告诉我标题已经加载。

我已经尝试了一些在线教程,但是当我添加内联 php 时,pdf 无法正确呈现。

是否可以添加外部 php 文件?

<?php

include config.php
$course_id= JRequest::getInt('cid');

$dbname = "i2894069_jos2";

// Create connection
$conn = new mysqli($servername, $username, $password, $dbname);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 

$sql = "SELECT en . * , e.full_name, e.level , c.base_level, s.station
FROM enrolled_students AS en
JOIN employees AS e ON en.student = e.user_id
JOIN stations AS s ON e.station = s.id
JOIN courses_instructed AS ci ON en.pid = ci.ci_id
JOIN courses as c on ci.ci_course = c.id
WHERE en.pid =$course_id
ORDER BY  e.last_name";
$result = $conn->query($sql);
?>

     <style>
.table-fixed thead {
  width: 97%;
}
.table-fixed tbody {
  height: 230px;
  overflow-y: auto;
  width: 100%;
}
.table-fixed thead, .table-fixed tbody, .table-fixed tr, .table-fixed td, .table-fixed th {
  display: block;
}
.table-fixed tbody td, .table-fixed thead > tr> th {
  float: left;
  border-bottom-width: 0;
}
        </style>

 <div class="row">
      <div class="panel panel-default">
        <div class="panel-heading">
          <h4>
            Fixed Header Scrolling Table 
          </h4>
        </div>
        <table class="table table-fixed">
          <thead>
            <tr>
              <th class="col-xs-4">Student</th><th class="col-xs-4">Station</th><th class="col-xs-4">Level</th>
            </tr>
          </thead>
          <tbody>
              <?php while($row = $result->fetch_assoc()) { 
              if($row['level'] == 11){
                     $level = 'Ambulette';
                 }elseif($row['level'] == 2){
                     $level = 'Dispatcher';
                  }elseif($row['level'] == 3){
                     $level = 'EMT';
                 }elseif($row['level'] == 4){
                     $level = 'AEMT';
                 }elseif($row['level'] == 5){
                     $level = 'Paramedic';
                 }elseif($row['level'] == 6){
                     $level = 'IT';
             }elseif($row['level'] == 7){
                     $level = 'RN / Medic';
             }
             else{$level = '';}

             $base_level = $row['base_level'];
             $elevel = $row['level'];

             if($elevel < $base_level){
                 $style = 'class="table-warning"';
             }else{
                 $style = '';
             }

              ?>
            <tr>
              <td class="col-xs-4"><?php echo $row['full_name'] ?></td><td class="col-xs-4"><?php echo $row['station'] ?></td><td class="col-xs-4"><?php echo $level ?></td>
            </tr>
              <?php } ?>
          </tbody>
        </table>
      </div>
  </div>  

【问题讨论】:

  • 您得到的究竟是什么错误信息?顶部的行应该是include 'config.php';;这可能会也可能不会解决您的问题。

标签: php html dompdf


【解决方案1】:

如果我对您的理解正确...您正在寻找的是这样的:

<?php

ob_start();
require 'yourtemplate.php'; // the one you posted in your question
$html = ob_get_clean();

现在您的 HTML 位于一个变量中,如果需要,您可以使用 DOMPDF 呈现它。

【讨论】:

    猜你喜欢
    • 2013-06-15
    • 2020-07-12
    • 2023-01-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-16
    相关资源
    最近更新 更多