Introducción a Zend Framework

 Aprendiendo Zend Framework

Apéndice

 Referencia de Zend Framework


  • Zend_Gdata
  • Zend_Http
  • Zend_InfoCard
  • Zend_Json
  • Zend_Layout
  • Zend_Ldap
  • Zend_Loader
  • Zend_Locale
  • Zend_Log
  • Zend_Mail
  • Zend_Markup
  • Zend_Measure
  • Zend_Memory
  • Zend_Mime
  • Zend_Navigation
  • Zend_Oauth
  • Zend_OpenId
  • Zend_Paginator
  • Zend_Pdf
  • Zend_ProgressBar
  • Zend_Queue
  • Zend_Reflection
  • Zend_Registry
  • Zend_Rest

  • Zend_Search_Lucene
  • Zend_Serializer
  • Zend_Server
  • Zend_Service
  • Zend_Session
  • Zend_Soap
  • Zend_Tag
  • Zend_Test
  • Zend_Text
  • Zend_TimeSync
  • Zend_Tool
  • Zend_Tool_Framework
  • Zend_Tool_Project
  • Zend_Translate
  • Zend_Uri
  • Zend_Validate
  • Zend_Version
  • Zend_View
  • Zend_Wildfire
  • Zend_XmlRpc
  • ZendX_Console_Process_Unix
  • ZendX_JQuery
  • Traducción al 26.9% - Actualizado el 2011-11-16 - Revisión 24249 - Versión ZF 1.11.x

    16.2. Barcode creation using Zend_Barcode class

    16.2.1. 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)

    Ejemplo 16.1. 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.

    // 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
    );

    Ejemplo 16.2. 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.

    // 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);

    16.2.2. Drawing a barcode

    When you draw the barcode, you retrieve the resource in which the barcode is drawn. To draw a barcode, you can call the draw() of the renderer, or simply use the proxy method provided by Zend_Barcode.

    Ejemplo 16.3. Drawing a barcode with the renderer object

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

    // No required options
    $rendererOptions = array();

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

    Ejemplo 16.4. Drawing a barcode with Zend_Barcode::draw()

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

    // No required options
    $rendererOptions = array();

    // Draw the barcode in a new image,
    $imageResource Zend_Barcode::draw(
        
    'code39''image'$barcodeOptions$rendererOptions
    );

    16.2.3. Renderering a barcode

    When you render a barcode, you draw the barcode, you send the headers and you send the resource (e.g. to a browser). To render a barcode, you can call the render() method of the renderer or simply use the proxy method provided by Zend_Barcode.

    Ejemplo 16.5. Renderering a barcode with the renderer object

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

    // No required options
    $rendererOptions = array();

    // Draw the barcode in a new image,
    // send the headers and the image
    Zend_Barcode::factory(
        
    'code39''image'$barcodeOptions$rendererOptions
    )->render();

    This will generate this barcode:


    Ejemplo 16.6. Renderering a barcode with Zend_Barcode::render()

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

    // No required options
    $rendererOptions = array();

    // Draw the barcode in a new image,
    // send the headers and the image
    Zend_Barcode::render(
        
    'code39''image'$barcodeOptions$rendererOptions
    );

    This will generate the same barcode as the previous example.


    digg delicious meneame google twitter technorati facebook

    Comentarios

    Loading...