2010-10-28 60 views
-1

我有一個工作的動態內容查詢/回聲文件,我需要將其轉換爲與domPDF一起使用的模板。會有人看我的代碼不執行,看看我要去哪裏錯了嗎?任何Smarty用戶在那裏?這是一個domPDF挑戰

(順便說一句,該sendPDF.tpl文件是在路徑:/ Smarty的/毫克/模板/ - sendPDF.php在/ Smarty的/毫克/和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); 

?> 
+1

這是什麼問題?什麼不起作用?你得到什麼錯誤信息?什麼是基本的調試,告訴你有關問題的根源 - 例如數據庫是否工作? – 2010-10-28 17:11:29

+0

Smarty將如何使用由「foreach」包圍的「while」聲明的簡單例子。謝謝艾倫 – artworthy 2010-10-28 17:13:07

+0

這個例程工作正常與演示文稿(回聲)集成的代碼。當我使用獨立於代碼的smarty模板時,我什麼也得不到。 (順便說一句,我是Smarty的新手) – artworthy 2010-10-28 17:16:30

回答

1

我沒有看到你做任何聰明的指派? 例如,你有一個PHP變量這裏:

$media = $row['media']; 

但是,這不會讓你的智者.tpl,除非你做這樣的事情:

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