2017-06-15 14 views
1

SymfonyのTWIGテンプレートにURLを入力することで、QRコードを動的に作りたいと思っています。私はendroid/QrCodeバンドルをインストールしても問題ありませんが、TWIGにQRコードイメージを作成する方法がわかりません! GitHubのページからそうsymfonyのTWIGでのエンドウンドQrコード

、それはTWIGがあるために言うすべて:

<img src="{{ qrcode_url('http://www.test.com') }}" /> 

Twig extension

The bundle provides a Twig extension for generating a QR code URL, path or data URI. You can use the second argument of any of these functions to override any defaults defined by the bundle or set via your configuration.

<img src="{{ qrcode_path(message) }}" /> 
<img src="{{ qrcode_url(message, { writer: 'eps' }) }}" /> 
<img src="{{ qrcode_data_uri(message, { writer: 'svg', size: 150 }) }}" /> 

だから私はテストのために考え出し、一番簡単な方法は、のようなものになるだろう

ただし、これによりエラーが発生します。

An exception has been thrown during the rendering of a template ("Unable to generate a URL for the named route "endroid_qrcode_generate" as such route does not exist.").

誰でもこの作業のためにTWIG拡張を取得しましたか?それはdocumentation

Add the following section to your routing to be able to handle QR code URLs. This step can be skipped if you only use data URIs to display your images.

に記載されているよう

+0

あなたは 'Symfony'の権利にバンドルを登録しましたか? – DarkBee

+0

確かに、AppKernel.phpでどうしたのか分からない場合は、関数を探す場所が分からないと思っています。qrcode_url – MicWit

+0

[QrController](https://github.com/)でルートが定義されています。あなたのキャッシュをクリアしましたか? – DarkBee

答えて

2

は、例えばへのルーティング設定を追加し、あなたがバンドルのルート設定を含めることを確認してくださいapp/config/routing.yml

EndroidQrCodeBundle: 
    resource: "@EndroidQrCodeBundle/Controller/" 
    type:  annotation 
    prefix: /qrcode 
+0

うまく動いていますが、コントローラ情報のように見えるので、この部分を必要としないTWIG拡張としてドキュメントを読んでいます。ありがとう。 – MicWit