2016-06-23 3 views
0

私はFOSJsRoutingBundleを使用しています。スクリプトタグにFOSJsRoutingBundleのルートを示す別の方法はありますか?

<script type="text/javascript" src="{{asset('bundles/fosjsrouting/js/router.js') }}"></script> 
<script type="text/javascript" src="{{ path('fos_js_routing_js', {"callback": "fos.Router.setData"}) }}"></script> 

をしかし、PDFファイルを生成するためにバンドルKnpSnappyBundleを使用しているとき、私は絶対に前のルートを指定する必要があり、次のように私は、小枝テンプレート内のファイルをリンクします。次のようにsymfonyの2.3を使用することにより、私は資産を使用してパスに変更されました:

<script type="text/javascript" src="{{app.request.scheme ~ '://' ~ app.request.httpHost ~ asset('bundles/fosjsrouting/js/router.js') }}"></script> 

私が持っているprobemは、他のルートは私にこのバンドルでエラーを与えることです。それを置く他の方法はありますか?上記と同じように置いてみましたが、pathの代わりにurlを使用しても動作しません。

これは私が持っているエラーです:

The exit status code '1' says something went wrong: 
stderr: "Loading pages (1/6) 
[> ] 0% 
[======> ] 10% 
QSslSocket: cannot resolve SSLv3_client_method 
QSslSocket: cannot resolve SSLv3_server_method 
[=======> ] 13% 
[==========> ] 18% 
[==========================> ] 44% 
[============================> ] 47% 
[==============================> ] 50% 
[==============================> ] 50% 
[===========================================> ] 73% 
[==============================================> ] 78% 
[============================================================] 100% 
Counting pages (2/6) 
[============================================================] Object 1 of 1 
Resolving links (4/6) 
[============================================================] Object 1 of 1 
Loading headers and footers (5/6) 
Printing pages (6/6) 
[> ] Preparing 
[============================================================] Page 1 of 1 
Done 
Exit with code 1 due to network error: ContentNotFoundError 
"stdout: "" 
command: /opt/lampp/htdocs/Symfony/app/../vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64 --lowquality --page-size 'A4' --viewport-size '‘1024x768’' '/tmp/knp_snappy576ad837d24a82.40556276.html' '/tmp/knp_snappy576ad837d25009.94614572.pdf'. 

これはコントローラです:

public function GenerarPdfFestivosAction() 
{ 

    $this->render(sprintf('BackendBundle:Festivos:calendario.pdf.twig')); 
    $em = $this->getDoctrine()->getManager(); 

    $inicio =$em->getRepository('BackendBundle:Centro')->findInicioCurso(); 
    $fin =$em->getRepository('BackendBundle:Centro')->findFinCurso(); 


    $html = $this->renderView('BackendBundle:Festivos:calendario.html.twig', array(
     'inicio' => $inicio, 
     'fin' => $fin, 
    )); 

    return new Response(
     $this->get('knp_snappy.pdf')->getOutputFromHtml($html), 
     200, 
     array(
      'Content-Type'  => 'application/pdf', 
      'Content-Disposition' => 'attachment; filename="Calendario.pdf"' 
     ) 
    ); 
} 

私はあなたの助けに感謝。

+0

何のエラー?なぜpdfを生成するためにjsルートが必要ですか? –

+0

こんにちは@SylvainGuilbert、私は必要ないくつかのデータを埋めるために別のTwigテンプレートを含むルートを生成する必要があります。 htmlを入手してください。しかし、このバンドルでpdfに変換すると、私にもルートのエラーが出ます。このバンドルでは、絶対パスを使用する必要がありますが、引き続き間違いがあります。ルートを含むCallback = fos.Router.setData'を生成する。ステートメントに追加したエラーです。私の場合、別のテンプレートの内容を 'load'で追加します:' $( 'container')load(Routing.generate( 'holidays_per_month'、{id:month})); ' – Joseph

+0

@SylvainGuilbertそうでなければ 'path( 'fos_js_routing_js'、{" callback ":" fos.Router.setData "})'を入れる方法はありますか? 私はそのルートについて本当に分かっていませんが、もっと明示的な指示があるかもしれません。私は生成するルート( 'holidays_per_month')と何か関係があるかどうかは分かりません。 – Joseph

答えて

0

あなたのPDFファイルが生成されますので(answer from here)のようにそれを使用することができます:あなたのコントローラで :

use Symfony\Component\HttpFoundation\BinaryFileResponse; 

    function generatePdfAction($param){ 
     $generator = $this->get('knp_snappy.pdf'); 
     $pdf = null; 
     $fileName = '/myDir/Calendario.pdf'; // change this 
     $inicio =$em->getRepository('BackendBundle:Centro')->findInicioCurso(); 
     $fin =$em->getRepository('BackendBundle:Centro')->findFinCurso(); 
     $html = $this->renderView('BackendBundle:Festivos:calendario.html.twig', array(
       'inicio' => $inicio, 
       'fin' => $fin, 
       )); 
     try { 
      $pdf = $generator->getOutputFromHtml($html); 
     } catch (\RuntimeException $e) { 
      $matches = []; 
      if (preg_match('/([^\']+)\'.$/', $e->getMessage(), $matches)) { 
       $pdf = file_get_contents($matches[1]); 
       unlink($matches[1]); 
      } else { 
       throw $e; 
      } 
     } 
     if ($pdf){ 
      file_put_contents($fileName, $pdf); 
      return new BinaryFileResponse($fileName); 
     } 
     else{ 
     // error message or smthing 
     } 
    } 
+0

こんにちは@SylvainGuilbert、このコードを使用するのは初めてです。私に問題を与える回線を使用しないで、私は自動的にpdfとコントローラをダウンロードします: '新しい返信( $ this-> get( 'knp_snappy.pdf') - > getOutputFromHtml($ html)、 200、 ( ) '' Content-Disposition '=>'添付ファイル名= "Calendario.pdf" ' ) )' – Joseph

+0

pdf生成のために、 –

+0

助けてくれてありがとう@SylvainGuilbert。私はコントローラをテストしてそのコードを修正し、動作させていない。ステートメントで使用するドライバを追加しました。どのように変更する必要がありますか? (コントローラーに表示される '$ inicio'と' $ fin'変数はデータをテンプレートに渡す必要があります)。 – Joseph

関連する問題