donate Buy us a cup of coffee
Our service is free. But your donation can help us keep running. To rent a server and domain, to buy us a cup of coffee, to reduce our activity in paid stuff and make this service better. You can send us a donation to BCA Bank, 008 090 8440 in the name of Abdul Malik Ikhsan with Swifcode CENAIDJA. Please confirm to samsonasik@gmail.com after that ;).
download Download module      



Barcode generation with Zend\Barcode sample usage

This example contains about How to use Barcode Component in Zend framework 2, The most important parts of using Barcode Component is the BarcodeObject that can be seen from the Barcode\ObjectPluginManager::invokableClasses

1. Barcode\ObjectPluginManager::invokableClasses property
    
        class ObjectPluginManager extends AbstractPluginManager
        {
            // ...
            protected $invokableClasses = array(
                'codabar'           => 'Zend\Barcode\Object\Codabar',
                'code128'           => 'Zend\Barcode\Object\Code128',
                'code25'            => 'Zend\Barcode\Object\Code25',
                'code25interleaved' => 'Zend\Barcode\Object\Code25interleaved',
                'code39'            => 'Zend\Barcode\Object\Code39',
                'ean13'             => 'Zend\Barcode\Object\Ean13',
                'ean2'              => 'Zend\Barcode\Object\Ean2',
                'ean5'              => 'Zend\Barcode\Object\Ean5',
                'ean8'              => 'Zend\Barcode\Object\Ean8',
                'error'             => 'Zend\Barcode\Object\Error',
                'identcode'         => 'Zend\Barcode\Object\Identcode',
                'itf14'             => 'Zend\Barcode\Object\Itf14',
                'leitcode'          => 'Zend\Barcode\Object\Leitcode',
                'planet'            => 'Zend\Barcode\Object\Planet',
                'postnet'           => 'Zend\Barcode\Object\Postnet',
                'royalmail'         => 'Zend\Barcode\Object\Royalmail',
                'upca'              => 'Zend\Barcode\Object\Upca',
                'upce'              => 'Zend\Barcode\Object\Upce',
            );
            // ...
        }
    
2. Then, we can consume via create our ObjectPluginManagerFactory :
    
        namespace LearnZF2Barcode\Factory\Service;

        use Zend\Mvc\Service\AbstractPluginManagerFactory;

        class BarcodeObjectPluginManagerFactory extends AbstractPluginManagerFactory
        {
            const PLUGIN_MANAGER_CLASS = 'Zend\Barcode\ObjectPluginManager';
        }
    
3. Register it into factories
    
    'service_manager' => [
        'factories' => [
            'BarcodeObjectPluginManager' => 'LearnZF2Barcode\Factory\Service\BarcodeObjectPluginManagerFactory',
        ],
    ],
    
3. Now, we can consume via BarcodeObjectPluginManager plugin manager

    var_dump(
        $serviceManager->get('BarcodeObjectPluginManager')->getRegisteredServices()['invokableClasses']
    );

4. Generate ? Use Zend\Barcode\Barcode class.
    
        $barcodeOptions = array('text' => '123456789');
        $barcode = Barcode::factory('codabar', 'image', $barcodeOptions);
        $barcode->draw()
    

By the way, you can find other examples using Zend Framework 2 in our home page :)