因此,我想通过在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