那里有 Smarty 用户吗?这是 domPDF 挑战

发布于 2024-09-30 03:39:54 字数 2648 浏览 6 评论 0原文

我有一个有效的动态内容查询/回显文件,我需要将其转换为模板以便与 d​​omPDF 一起使用。有人会查看我未执行的代码来看看我哪里出了问题吗?

(顺便说一句,sendPDF.tpl 文件位于路径:/Smarty/mg/templates/ - sendPDF.php 位于 /Smarty/mg/ 中,smartyTEST.php 位于我的根路径中)

*****sendPDF.php********
<?php
include_once "scripts/connect_to_mysql.php";
session_start();
$art_id=$_SESSION['art_id'];

require '../libs/Smarty.class.php';


$message = "test page here";
$path0 = "artWorkImages/";
$path = "myGallerist/artWorkImages/";

foreach ($art_id as $art_id0){
//print_r("..id".$art_id0);
   $QUERY="SELECT * FROM artWork WHERE art_id = '$art_id0' ";
    $res = mysql_query($QUERY);
   $num = mysql_num_rows($res);
   if($num>0){

   while($row = mysql_fetch_array($res)){
       $art_title = $row['art_title'];
       $art_id = $row['art_id'];
       $rep_email = $row['rep_email'];
       $make_avail = $row['make_avail'];
         $media = $row['media'];
         $height_in = $row['height_in'];
         $width_in = $row['width_in']; 
         $depth_in = $row['depth_in'];
         $height_cm = $row['height_cm'];
         $width_cm = $row['width_cm']; 
         $depth_cm = $row['depth_cm'];
         $art_year = $row['art_year'];      
       $about_art = $row['about_art'];
       $image_link = $row['image_link'];
           $location = $row['location'];
       $price = $row['price'];
       $curency = $row['curency'];
       $sale = $row['sale'];
       }
   }
}

$smarty->display('sendPDF.tpl');

?>

*******sendPDF.tpl*************
            <tr align="left" padding="3">
            <td align="left" width="80%" >
            <img src="slir/w500-h500/$path$image_link" ></a><br />
            $art_title, $media, $art_year<br />
            $height_in h x $width_in w x $depth_in d inches<br />
            $height_cm h x $width_cm w x $depth_cm d cm<br />

            Location: $location<br />
            Price: $price $curency<br />
            Sales/Contact email: $rep_email</td>
        <td align="left" width="20%"></td>
</tr>

**********smartyTEST.php*****************

<?php
///     Connect to database
include_once "scripts/connect_to_mysql.php";
//include the dom pdf
require('dompdf/dompdf_config.inc.php');

//fetch the HTML output from smarty template
$htmlcontent=$smarty->fetch('sendPDF.tpl');

//call dom pdf class
$dompdf = new DOMPDF();
$dompdf->load_html($htmlcontent);
$dompdf->render();
//display output in browser
$dompdf->stream(110272009.pdf);
//or, save as a pdf
///$pdf = $dompdf->output();
///file_put_contents("tmp/filename.pdf", $pdf);

?>

I have a working dynamic content query/echo file that I need to convert to template for use with domPDF. Would someone look at my code that's not executing to see where I'm going wrong?

(Btw, the sendPDF.tpl file is in path: /Smarty/mg/templates/ -- sendPDF.php is in /Smarty/mg/ and smartyTEST.php is in my root path)

*****sendPDF.php********
<?php
include_once "scripts/connect_to_mysql.php";
session_start();
$art_id=$_SESSION['art_id'];

require '../libs/Smarty.class.php';


$message = "test page here";
$path0 = "artWorkImages/";
$path = "myGallerist/artWorkImages/";

foreach ($art_id as $art_id0){
//print_r("..id".$art_id0);
   $QUERY="SELECT * FROM artWork WHERE art_id = '$art_id0' ";
    $res = mysql_query($QUERY);
   $num = mysql_num_rows($res);
   if($num>0){

   while($row = mysql_fetch_array($res)){
       $art_title = $row['art_title'];
       $art_id = $row['art_id'];
       $rep_email = $row['rep_email'];
       $make_avail = $row['make_avail'];
         $media = $row['media'];
         $height_in = $row['height_in'];
         $width_in = $row['width_in']; 
         $depth_in = $row['depth_in'];
         $height_cm = $row['height_cm'];
         $width_cm = $row['width_cm']; 
         $depth_cm = $row['depth_cm'];
         $art_year = $row['art_year'];      
       $about_art = $row['about_art'];
       $image_link = $row['image_link'];
           $location = $row['location'];
       $price = $row['price'];
       $curency = $row['curency'];
       $sale = $row['sale'];
       }
   }
}

$smarty->display('sendPDF.tpl');

?>

*******sendPDF.tpl*************
            <tr align="left" padding="3">
            <td align="left" width="80%" >
            <img src="slir/w500-h500/$path$image_link" ></a><br />
            $art_title, $media, $art_year<br />
            $height_in h x $width_in w x $depth_in d inches<br />
            $height_cm h x $width_cm w x $depth_cm d cm<br />

            Location: $location<br />
            Price: $price $curency<br />
            Sales/Contact email: $rep_email</td>
        <td align="left" width="20%"></td>
</tr>

**********smartyTEST.php*****************

<?php
///     Connect to database
include_once "scripts/connect_to_mysql.php";
//include the dom pdf
require('dompdf/dompdf_config.inc.php');

//fetch the HTML output from smarty template
$htmlcontent=$smarty->fetch('sendPDF.tpl');

//call dom pdf class
$dompdf = new DOMPDF();
$dompdf->load_html($htmlcontent);
$dompdf->render();
//display output in browser
$dompdf->stream(110272009.pdf);
//or, save as a pdf
///$pdf = $dompdf->output();
///file_put_contents("tmp/filename.pdf", $pdf);

?>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨夜星沙 2024-10-07 03:39:54

我没看到你在做任何聪明的任务?
例如,您在这里有一个 PHP 变量:

 $media = $row['media'];

但是除非您执行以下操作,否则它不会到达您的 smarty .tpl:

$smarty->assign("media",$media);

I'm not seeing you doing any smarty assigns?
For instance, you have a PHP variable here:

 $media = $row['media'];

But that will not get to your smarty .tpl unless you do something like this:

$smarty->assign("media",$media);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文