mopa/barcode-bundle

该软件包最新版本(dev-master)没有可用的许可证信息。

集成Zend_Barcode和PHP QR Lib,以便通过twig在symfony2中轻松使用

安装次数66,879

依赖项: 1

建议者: 0

安全: 0

星标: 43

关注者: 7

分支: 25

公开问题: 5

类型:symfony-bundle

dev-master 2015-05-30 16:36 UTC

This package is auto-updated.

Last update: 2024-09-19 10:43:05 UTC


README

简介

MopaBarcodeBundle集成Zend_Barcode和PHP QR Lib,以便通过twig在symfony2中轻松使用。由于其配置的变化,我包含了phpqrcode,这只是个尝试,不应被视为完美。请随意fork和PR。

先决条件

安装

  1. 将此软件包添加到您的composer.json文件中
{
    "require": {
        // ...
        "mopa/barcode-bundle": "dev-master",
        "avalanche123/imagine-bundle": "dev-master", // 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
    }
}
  1. 将此软件包添加到您的app/AppKernel.php文件中
// application/ApplicationKernel.php
public function registerBundles()
{
    return array(
        // ...
        new Avalanche\Bundle\ImagineBundle\AvalancheImagineBundle(),
        new Mopa\Bundle\BarcodeBundle\MopaBarcodeBundle(),
    );
}

演示

在您的app中包含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。服务中给出的类型是types数组键和值中定义的int或字符串

要在控制器等中获取服务,可以使用以下方法

$bmanager = $this->container->get('mopa_barcode.barcode_service');

$bmanager->saveAs($type, $text, $file); 保存类型为$btype,文本为$text的条码到文件$file或

$bmanager->get($type, $enctext, $absolute = false); 获取文件的URL,其中$enctext是经过URL编码的,$absolute是一个布尔值,用于获取绝对路径或相对路径(默认)

Twig Helper

还有一个注册的twig helper

        <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布尔值,这里不再进一步解释

直接使用软件包

要在您的应用程序中使用示例游乐场,只需将playground.html.twig复制到app/Resources/MopaBootstrapBundle/views/Barcode/playground.html.twig,并根据需要修改

作为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代码级别(大小),您必须生成叠加图像。例如,查看软件包的`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