因此,我想通過在Symfony中的TWIG模板中提供一個URL來動態創建QR代碼。我安裝了endroid/QrCode軟件包,似乎很好,但我不確定如何讓TWIG創建QR碼圖像!Symfony中的TWIG中的endroid Qr代碼
從GitHub的頁面因此,所有它說的嫩枝是:
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 }) }}" />
所以我想通了一個測試,最容易做的事情會是這樣的:
<img src="{{ qrcode_url('http://www.test.com') }}" />
但是,這帶來了錯誤:
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擴展?
您確實在'Symfony'右邊註冊了包? – DarkBee
當然,在AppKernel.php中如果我沒有,我不認爲它甚至會知道在哪裏尋找函數qrcode_url – MicWit
那麼在[QrController]中定義了路由(https://github.com/ endroid/QrCode/blob/master/src/Bundle/Controller/QrCodeController.php),你是否在添加bundle後清除緩存? – DarkBee