PhpRiot
Become Zend Certified

Prepare for the ZCE exam using our quizzes (web or iPad/iPhone). More info...


When you're ready get 7.5% off your exam voucher using voucher CJQNOV23 at the Zend Store

Using Zend_Barcode::factory

Zend_Barcode uses a factory method to create an instance of a renderer that extends Zend_Barcode_Renderer_RendererAbstract. The factory method accepts five arguments.

  1. The name of the barcode format (e.g., "code39") (required)

  2. The name of the renderer (e.g., "image") (required)

  3. Options to pass to the barcode object (an array or Zend_Config object) (optional)

  4. Options to pass to the renderer object (an array or Zend_Config object) (optional)

  5. Boolean to indicate whether or not to automatically render errors. If an exception occurs, the provided barcode object will be replaced with an Error representation (optional default TRUE)

Example 59. Getting a Renderer with Zend_Barcode::factory()

Zend_Barcode::factory() instantiates barcode objects and renderers and ties them together. In this first example, we will use the Code39 barcode type together with the Image renderer.

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

// No required options
$rendererOptions = array();
$renderer Zend_Barcode::factory(
    
'code39''image'$barcodeOptions$rendererOptions
);

Example 60. Using Zend_Barcode::factory() with Zend_Config objects

You may pass a Zend_Config object to the factory in order to create the necessary objects. The following example is functionally equivalent to the previous.

<?php
// Using only one Zend_Config object
$config = new Zend_Config(array(
    
'barcode'        => 'code39',
    
'barcodeParams'  => array('text' => 'ZEND-FRAMEWORK'),
    
'renderer'       => 'image',
    
'rendererParams' => array('imageType' => 'gif'),
));

$renderer Zend_Barcode::factory($config);

Zend Framework