如何在视图中访问 ZF2 条码
How To access ZF2 Barcode in view
我想在一个页面上呈现多个 Zend Framework 2 条形码。
我一直在关注这个例子(虽然它是针对ZF1的)
Zend Framework Render Barcodes Into PDF Pages
我目前正在使用 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
我得到:
"resource(459) of type (gd)"
当我使用 imagegd()
时,我得到了一堆符号。
不确定我是否走上了最佳道路。
最后我想 运行 通过 foreach
获取每个条形码的图像,我可以将其添加到 pdf 中。
有a lot of documentation available on the ZF2 BarCode
class。在那里你可以找到如何将条形码渲染成图像的解释:
$barCode = Barcode::factory(
'code39', 'image', $barcodeOptions, $rendererOptions
)->render();
要传递给您的视图,您可以这样做:
new ViewModel(array('barCode' => $barCode));
我将它们作为 link 添加到 html 中,如下所述 link。
How to render several barcodes with Zend 2?
我想在一个页面上呈现多个 Zend Framework 2 条形码。
我一直在关注这个例子(虽然它是针对ZF1的) Zend Framework Render Barcodes Into PDF Pages
我目前正在使用 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
我得到:
"resource(459) of type (gd)"
当我使用 imagegd()
时,我得到了一堆符号。
不确定我是否走上了最佳道路。
最后我想 运行 通过 foreach
获取每个条形码的图像,我可以将其添加到 pdf 中。
有a lot of documentation available on the ZF2 BarCode
class。在那里你可以找到如何将条形码渲染成图像的解释:
$barCode = Barcode::factory(
'code39', 'image', $barcodeOptions, $rendererOptions
)->render();
要传递给您的视图,您可以这样做:
new ViewModel(array('barCode' => $barCode));
我将它们作为 link 添加到 html 中,如下所述 link。
How to render several barcodes with Zend 2?