symfony3でpdfを使用するknpsnappybundleのチュートリアルに従っていますが、問題はPDFのページに値の配列を渡す必要があるためです。元のページのような完全なページを得ることができますPDF生成に問題Symfony 3
ここでコントローラである:ここで
public function pdfAction(){
$html = $this->renderView('@Recommendation/Recommendation/payment-successful.html.twig');
$filename = sprintf('test.pdf', date('Y-m-d'));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('inline; filename="%s"', $filename),
]
);
}
は、印刷ボタンコードと通常のページの写真である:
<a href="{{ path('payment_pdf') }}"><button>PRINT</button></a>
及び経路:
payment_pdf:
path: /payment_pdf
defaults: { _controller: "RecommendationBundle:Recommendation:pdf"}
私のオリジナルのページの画像:今、PDFの画像が生成さ https://i.stack.imgur.com/3MBEt.png
と:あなたはテーブルが空であることがわかり https://i.stack.imgur.com/rqs2x.png
!
画像を表示することはできません申し訳ありません
小枝ファイル:
<head>
<script type="text/javascript" src="http://yourjavascript.com/12191816011/success.js"></script>
<link rel="shortcut icon" href="http://www.iconj.com/ico/f/k/fksvrhslsa.ico" type="image/x-icon" />
<script type="text/javascript" src="http://yourjavascript.com/11396113712/jquery-ajax-deprecated-dimensions-effects-offset-wrap-min.js"></script>
<link href="https://dl.dropboxusercontent.com/s/6dgxerbf1p6p8zl/styles.css" rel="stylesheet" type="text/css">
</head>
<html>
<div class="pf-checkout-container pf-success-page">
<h1 class="pf-green">Payment Successful</h1>
<p class="pf-processed-msg">Your payment has been processed! Details of the transaction are included below:</p>
<div class="pf-total-col">
<span class="pf-total-paid">Amount Paid</span>
<div class="pf-total-wrapper">
<span class="pf-total-label">Total:</span>
<span class="pf-total-amount pf-green" id="pf-total-amount">$00.00</span>
</div>
</div>
<div class="pf-success-details">
<p>Thank you for your purchase. Be sure to check us out on Facebook & Twitter!</p>
<div class="pf-success-info">
<ul>
<li>
<span class="pf-value-name">Name:</span>
<span id="pf-full-name" class="pf-value">{{ app.user.username }}</span>
</li>
<li>
<span class="pf-value-name">Auth Code:</span>
<span class="pf-value">{{app.user.salt}}</span>
</li>
</ul>
<br>
<br>
<table width="100%" border="1" cellpadding="10" style="font-family:'Myriad Pro' ">
<tr>
<th width="43%" align="left">Product Name</th>
<th width="10%">Unit Price</th>
<th width="10%">Quantity</th>
<th width="12%">Total</th>
</tr>
{% if livres is defined %}
{% for l in livres %}
<tr bgcolor="#FFFFFF" class=" product-detail">
<td valign="top">{{ l.titre }}</td>
<td align="center" valign="top">{{ l.prix }} DT</td>
<td align="center" valign="top">{{ l.quantite}}</td>
<td align="center" valign="top">{{ l.prix}} DT</td>
</tr>
{% endfor %}
{% endif %}
</table>
</div>
<!-- | PUT YOUR COMPANY LOGO HERE | -->
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</div>
<div class="pf-payment-buttons">
<!-- | PUT YOUR LINK HERE | -->
<button>Back to Store</button>
<!-- ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
</div>
<a href="{{ path('payment_pdf') }}"><button>PRINT</button></a>
<div class="pf-footer">
<img src="https://stripe.com/img/v3/home/social.png" />
</div>
</div>
</html>
私の完全なコントローラファイル:
class RecommendationController extends Controller
{
public function afficheAction()
{
$em = $this->getDoctrine()->getManager();
$recommendation = $em->getRepository("MainBundle:Recommendation")->findAll();
return $this->render("RecommendationBundle:Recommendation:book_detail.html.twig", array('recom' => $recommendation));
}
public function afficheparidAction($id)
{
$em = $this->getDoctrine()->getManager();
$em1 = $this->getDoctrine()->getManager();
$livre = $em->getRepository('MainBundle:Livre')->find($id);
$recommendation = $em1->getRepository('MainBundle:Recommendation')->findAll();
return $this->render('RecommendationBundle:Recommendation:book_detail.html.twig', array(
'livre' => $livre, 'recom' => $recommendation
));
}
public function AjoutAction($id)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$livre = $em->getRepository('MainBundle:Livre')->find($id);
$rec = new Recommendation();
if (isset($_POST['review'])) {
$rec->setIdUtilisateur($user);
$rec->setContenu($_POST['review']);
$rec->setIdLivre($livre);
$em->persist($rec);
$em->flush();
//返信$ this-> redirectToRoute( "recommendation_bookid"); return $ this-> redirect($ this-> generateUrl( 'recommendation_new'、array( 'id' => $ id)));
}
$em1 = $this->getDoctrine()->getManager();
$recommendation = $em1->getRepository('MainBundle:Recommendation')->findAll();
return $this->render("RecommendationBundle:Recommendation:new_rec.html.twig", array('livre' => $livre, 'id' => $id, 'recom' => $recommendation));
}
public function DeleteAction($id_r, $id_l)
{
$em = $this->getDoctrine()->getManager();
$rec = $em->getRepository('MainBundle:Recommendation')->find($id_r);
$livre = $em->getRepository('MainBundle:Livre')->find($id_l);
$em->remove($rec);
$em->flush();
$em1 = $this->getDoctrine()->getManager();
return $this->redirect($this->generateUrl('recommendation_new', array('livre' => $livre, 'id' => $livre->getId())));
}
public function UpdateAction($id_r,$id_l)
{
$user = $this->getUser();
$em = $this->getDoctrine()->getManager();
$rec = $em->getRepository('MainBundle:Recommendation')->find($id_r);
$em->remove($rec);
$em->flush();
$livre = $em->getRepository('MainBundle:Livre')->find($id_l);
if (isset($_POST['review'])) {
$rec->setId($id_r);
$rec->setIdUtilisateur($user);
$rec->setContenu($_POST['review']);
$rec->setIdLivre($livre);
$em->persist($rec);
$em->flush();
return $this->redirect($this->generateUrl('recommendation_new', array('id' => $id_l)));
}
}
public function FindAction($id_l,$id_r)
{
$em = $this->getDoctrine()->getManager();
$em1 = $this->getDoctrine()->getManager();
$rec = $em->getRepository('MainBundle:Recommendation')->find($id_r);
$livre = $em1->getRepository('MainBundle:Livre')->find($id_l);
return $this->render('RecommendationBundle:Recommendation:edit_rec.html.twig', array('rec' => $rec, 'livre' =>$livre));
}
public function bookAction()
{
return $this->render('RecommendationBundle:Recommendation:book_detail.html.twig');
}
public function cartAction($id)
{if (!isset($_SESSION['cart'])){
$_SESSION['cart']=array();}
$em = $this->getDoctrine()->getManager();
$livre = $em->getRepository('MainBundle:Livre')->find($id);
// if (isset($_SESSION['book'])) {
$_SESSION['cart'][$id] = $livre;
$cart=$_SESSION['cart'];
リターンます$ this->レンダリング( 'RecommendationBundle:推奨:cart.html.twig'、配列( 'ID' => $ ID 'のlivres' => $カート));
}
public function emptycartAction()
{
//if (isset($_SESSION['cart'])) {
$_SESSION['cart'] = array();
$cart=$_SESSION['cart'];
return $this->render('RecommendationBundle:Recommendation:cart.html.twig',array('livres'=>$cart));
}
public function removebookcartAction($id)
{
// {if (isset($_SESSION['cart'])){
unset($_SESSION['cart'][$id]);
$cart=$_SESSION['cart'];
// return $this->redirect($this->generateUrl('recommendation_cart_affiche', array('livres' => $cart)));
戻りの$ this - > redirectToRoute( 'recommendation_cart_show'、配列( 'のlivres' => $カート))。 // $ this-> render( 'RecommendationBundle:Recommendation:cart.html。( 'id' => 1、 'livres' => $ cart));
}
public function showAction(){
// if(!empty($_SESSION['cart']))
$livres=$_SESSION['cart'];
return $this->render('RecommendationBundle:Recommendation:cart.html.twig',array('livres'=>$livres));
}
public function okAction($cart){
$cart=$_SESSION['cart'];
return $this->render('RecommendationBundle:Recommendation:payment-successful.html.twig',array('livres'=>$cart));
}
public function pdfAction($cart){
// $cart=$_SESSION['cart'];
$html = $this->renderView('@Recommendation/Recommendation/payment_pdf.html.twig',array('livres'=>$cart));
$filename = sprintf('test.pdf', date('Y-m-d'));
return new Response(
$this->get('knp_snappy.pdf')->getOutputFromHtml($html),
200,
[
'Content-Type' => 'application/pdf',
'Content-Disposition' => sprintf('inline; filename="%s"', $filename),
]
);
}
マイルート:
recommendation_bookid: パス:/ book_detail/{ID} デフォルト:{_controller: "RecommendationBundle:勧告:afficheparid"} recommendation_book: パス:/ book_detail デフォルト:{_controller: "RecommendationBundle:Recom mendation:affiche」} recommendation_new: パス:/ book_detail/{ID} /新しい デフォルト:{_controller: "RecommendationBundle:勧告:Ajout"} recommendation_delete: パス:/ book_detail/{ID_L}/{単位のId_R}/{_controller: "RecommendationBundle:推奨:削除"} recommendation_edit: パス:/ book_detail/{ID_L}/{単位のId_R} /編集 デフォルト:{_controller: "RecommendationBundle:勧告:アップデート"} recommendation_find デフォルト値を削除します。 パス:/ book_detail/{id_l}/{id_r}/find デフォルト:{_controller: "RecommendationBundle:Recommendation:Find"} recommendation_cart: パス:/ book_detail/{ID} /カート デフォルト:{_controller: "RecommendationBundle:勧告:カート"} recommendation_empty: パス:/ emptycart デフォルト:{_controller: "RecommendationBundle:勧告:emptycart"} recommendation_cart_remove。 パス:/ remove_book/{ID} デフォルト:{_controller: "RecommendationBundle:勧告:removebookcart"} recommendation_cart_show: パス:/ remove_book デフォルト:{_controller: "RecommendationBundle:勧告:ショー"} payment_ok: パス:/ payment_success デフォルト:{_controller: "RecommendationBundle:Recommendati上:OK "}
payment_pdf: パス:/ payment_pdf デフォルト:{_controller: "RecommendationBundle:推奨:PDF"}
のように考えられていますので、
私はSESSION配列で働いていますか? –
pdfページ 上記のようなpdfページを生成するアクションpayment_pdfに私を連れて行きます –
あなたが変更を行う前と後にあなたの小枝ファイル 'payment-successful.html.twig'を表示できますか?あなたが古いものを持っていない場合、現在のものです。 –