2016-12-05 1 views
2

J'ai créé une fonction php pour télécharger le pdf dans cakephp mais je ce téléchargement fonctionne juste quand j'ai IDM dans mon navigateur, quand j'ai désactivé IDM je n'ai rien, c'est mes pages de code : fonction de contrôleur:voir le pdf sur le navigateur dompdf dans cakephp

public function admin_pdf() 
{ 
$this->layout="pdf"; 
$tpl_dash = array(); 
$date = ""; 
if(isset($_POST['month']) && isset($_POST['year'])){ 
    ..... 
} 
    $this->set('tpl_dash',$tpl_dash); 
} 

ceci est mon avis fichier pdf:

<div class="container"> 
<div class="row"> 
    <div class="gap"></div> 
    <div class="product-thumb product-thumb-horizontal"> 
     <h2 class="pull-left">Statistiques des Etablissements</h2> 
     <table class="table table-hover table-striped table-bordered" id="tpl-dashboard"> 
      <thead> 
       <tr> 
        <th colspan="2" class="first-th"></th> 
        <th colspan="3" class="first-th">Winz</th> 
        <th colspan="3" class="first-th">Réservation</th> 
        <th colspan="3" class="first-th">Avis et Notes</th> 
       </tr> 
       <tr> 
        <th>Etablissement</th> 
        <th>Ville</th> 
        <th>Nbre de Winz validés</th> 
        <th>Nbre de Winz consommés</th> 
        <th>Nbre de Winz non consommés</th> 
        <th>Nbre des Réservations validées</th> 
        <th>Nbre des Réservations consommées</th> 
        <th>Nbre des Réservations non consommées</th> 
        <th>Nbre Avis</th> 
        <th>Nbre Notes</th> 
        <th>Nbre Favoris</th> 
       </tr> 
      </thead> 
      <tbody> 
       <?php foreach ($tpl_dash as $key => $value): ?> 
        <tr> 
         <td><?php echo $value['nom'] ?></td> 
         <td><?php echo $value['ville'] ?></td> 
         <td><?php echo $value['avis'] ?></td> 
         <td><?php echo $value['notes'] ?></td> 
         <td><?php echo $value['favoris'] ?></td> 
         <td><?php echo $value['winzsValides'] ?></td> 
         <td><?php echo $value['winzsConsommes'] ?></td> 
         <td><?php echo $value['winzsNonConsommes'] ?></td> 
         <td><?php echo $value['reservationValidees'] ?></td> 
         <td><?php echo $value['reservationConsommees'] ?></td> 
         <td><?php echo $value['reservationNonConsommees'] ?></td> 
        </tr> 
       <?php endforeach; ?> 
      </tbody> 
     </table> 
    </div> 
</div> 

et ceci est mon pdf lyaout:

require_once (APP . 'Plugin' . DS . 'dompdf' . DS . 'autoload.inc.php'); 

$dompdf = new Dompdf\Dompdf(); 
$dompdf->load_html($this->fetch('content')); 
//$dompdf->loadHtml($this->fetch('content');); 
// (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(); 

Je tentais de faire ce $dompdf->stream('my.pdf',array('Attachment'=>0)); et je tentais de faire Attachment sur ture, mais à la fois toujours pas

+0

Can vous s'il vous plaît clarifier comment cela n'a pas fonctionné? Cliquez sur ne donne aucune activité? Message d'erreur? etc. – Jason

+0

oui quand je clique je n'ai rien, mais si j'ai IDM dans mon navigateur le téléchargement pdf quand je clique –

Répondre

1

Je résous le problème, dans le premier script que je travaillais avec ajax pour télécharger pdf mais travaillant seulement avec IDM.

function printPdf() { 
    var m = document.getElementById("month"); 
    var y = document.getElementById("year"); 
    var month = m.options[m.selectedIndex].value; 
    var year = y.options[y.selectedIndex].value; 
    var monthText = m.options[m.selectedIndex].text; 
    var dataString = 'month='+month+'&year='+year+'&monthText='+monthText; 
    $.ajax({ 
     type: "POST", 
     url: "/admin/pages/pdf", 
     data: dataString, 
     cache: false, 
     success: function(result){ 

     } 
    }); 
} 

si je ne IDM dans mon navigateur je ne peux pas le télécharger, mais maintenant je supprimer la fonction printPdf() et je mis le générateur de buttom pdf sous forme, maintenant PDF a été chargé dans le navigateur