繁体   English   中英

如何在视图中访问ZF2条形码

[英]How To access ZF2 Barcode in view

我想在页面上呈现多个Zend Framework 2条码。

我一直在关注此示例(尽管它适用于ZF1), Zend Framework会将条形码渲染为PDF页面

我目前正在使用DOMPDFModule创建pdf。

如何使用ZF2显示条形码? 如何在视图中渲染它们?

    // Only the text to draw is required
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');

    // No required options
    $rendererOptions = array(
        'imageType' => 'gif'
    );

    // Draw the barcode in a new image,
    $imageResource  = Barcode::factory(
        'code39', 'image', $barcodeOptions, $rendererOptions
    )->draw();

当我var_dump $imageResource我得到:

“类型(gd)的资源(459)”

当我使用imagegd() ,会得到很多符号。

不知道我要走最好的路。

最后,我想遍历一个foreach以获得每个条形码的图像,然后可以将其添加到pdf中。

ZF2 BarCode类上有很多文档 在那里您找到了解释如何将条形码渲染为图像的方法:

$barCode = Barcode::factory(
    'code39', 'image', $barcodeOptions, $rendererOptions
)->render();

要传递您的意见,您可以执行以下操作:

new ViewModel(array('barCode' => $barCode)); 

我将它们添加为html中的链接,如下面的链接所述。

如何使用Zend 2渲染多个条形码?

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM