2010-10-28 35 views
-1

J'ai un fichier de requête/echo de contenu dynamique que je dois convertir en template pour l'utiliser avec domPDF. Est-ce que quelqu'un regarderait mon code qui ne s'exécute pas pour voir où je vais mal?Des utilisateurs de Smarty? Voici un défi domPDF

(BTW, le fichier sendPDF.tpl est dans le chemin:/Smarty/mg/templates/- sendPDF.php est dans/Smarty/mg/et smartyTEST.php est dans mon chemin racine)

*****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

Quel est le problème? Qu'est-ce qui ne fonctionne pas? Quels messages d'erreur obtenez-vous? Qu'est-ce que le débogage de base qui vous parle de la source du problème - la base de données fonctionne-t-elle, par exemple? –

+0

un exemple simple de la façon dont Smarty fonctionnerait avec une instruction «while» encadrée par un «foreach». Merci Allen – artworthy

+0

Cette routine fonctionne très bien avec le code intégré à la présentation (echo). Je n'ai rien quand j'utilise le template smarty séparé du code. (btw, je suis nouveau à Smarty) – artworthy

Répondre

1

Je ne vous vois pas faire des affectations intelligentes? Par exemple, vous avez une variable PHP ici:

$media = $row['media']; 

Mais cela ne se rendre à votre Smarty tpl à moins que vous fassiez quelque chose comme ceci:

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