mopa-liip / barcode-bundle
集成Zend_Barcode和PHP QR Lib,便于在symfony2中通过twig使用
Requires
- php: >=5.3.2
- liip/imagine-bundle: ^1.2.6
- symfony/framework-bundle: ~2.3
- symfony/twig-bundle: ~2.3|~3.0
- zendframework/zend-barcode: ~2.3.7
- zendframework/zend-servicemanager: ~2.3.7
- zendframework/zend-validator: ~2.3.7
Requires (Dev)
- phpunit/phpunit: ~4.6
Suggests
- symfony/monolog-bundle: ^1.0
This package is not auto-updated.
Last update: 2024-09-14 18:36:50 UTC
README
简介
MopaBarcodeBundle通过集成Zend_Barcode和PHP QR Lib,便于在symfony2中通过twig使用。由于PHP QR Lib配置的变化,我包含了phpqrcode。这只是个尝试,不应被视为完美。欢迎fork和PR。
先决条件
安装
- 将此包添加到您的composer.json
{
"require": {
// ...
"mopa-liip/barcode-bundle": "*",
"liip/imagine-bundle": "*", // handles image installation via requirements
// if you want to use the zend barcodes
"zendframework/zend-barcode": "~2.3.7",
"zendframework/zend-servicemanager": "~2.3.7",
// optionally for playground
"mopa/bootstrap-sandbox-bundle": "dev-master"
// also read the readme:
// https://github.com/phiamo/MopaBootstrapSandboxBundle
}
}
- 将此包添加到您的app/AppKernel.php
// application/ApplicationKernel.php public function registerBundles() { return array( // ... new Liip\ImagineBundle\LiipImagineBundle(), new Mopa\Bundle\BarcodeBundle\MopaBarcodeBundle(), ); }
演示
在您的应用中包含MopaBoostrapBundle: https://github.com/phiamo/MopaBootstrapBundle
在您的routing.yml中包含此片段
my_barcode_playground: resource: "@MopaBarcodeBundle/Resources/config/routing/barcode_playground.yml" prefix: /
将此添加到您的config.yml
imports: - { resource: @MopaBootstrapSandboxBundle/Resources/config/examples/example_menu.yml } - { resource: @MopaBootstrapSandboxBundle/Resources/config/examples/example_navbar.yml }
然后尝试 http://{yoursymfonyapp}/mopa/barcode/playground
用法
查看https://github.com/phiamo/MopaBarcodeBundle/blob/master/Controller/BarcodeController.php以了解其用法
支持的条码类型取决于您的Zend2安装
如果您已安装,请查看https://github.com/phiamo/MopaBarcodeBundle/blob/master/Model/BarcodeTypes.php。服务中给出的类型是类型数组键和值的int或字符串
要获取控制器中的服务,您可以使用
$bmanager = $this->container->get('mopa_barcode.barcode_service');
$bmanager->saveAs($type, $text, $file); 保存类型为 $type,文本为 $text 的条码到文件 $file 或
$bmanager->get($type, $enctext, $absolute = false); 获取文件的URL,其中 $enctext 是url编码的,$absolute 是布尔值,用于获取绝对路径或相对路径(默认)
Twig助手
还有一个注册的twig助手
<p><img alt="[barcode]" src="{{ mopa_barcode_url('code128', '123456789', {'barcodeOptions': {}, 'rendererOptions': {}}) }}"></p>
当然,字典(第三个参数是可选的)可以查看http://framework.zend.com/manual/2.1/en/modules/zend.barcode.creation.html以了解可以设置哪些选项。
字典还接受一个noCache布尔值,这里不再进一步解释
直接使用Bundle
要使用示例中的Playground,只需将playground.html.twig复制到app/Resources/MopaBootstrapBundle/views/Barcode/playground.html.twig,并按需修改
将Bundle作为URL服务使用
如果您想即时生成条码,请包含在您的routing.yml中
my_barcode_display: resource: "@MopaBarcodeBundle/Resources/config/routing/barcode_display.yml" prefix: /
然后只需使用URL生成您的条码
http://{yoursymfonyapp}/mopa/barcode/send/{type}/{enctext}
使用QR代码叠加
将此添加到twig模板。
<img src="{{ mopa_barcode_url('qr', "Text to put in QR code", {'size':2, 'level':3, 'margin':0, 'useOverlay': true}) }}"/>
更改叠加图像
将此添加并编辑到您的parameters.yml文件。
mopa_barcode.overlay_images_path: Resources/qr_overlays
对于每个QR代码级别(大小),您都必须生成叠加图像。例如,查看bundle的`Resources/qr_overlays`路径中的叠加图像。
待办事项
- Load the different Barcode Libs in a different way. should't be done by ints :(
已知问题
- Nothing what could not be done in another way, probably some will arise as soon as its published
So make issues!
- There are probably things missing, so make PR's