CodeIgniter 2 + Zend 2 library barcode

自古美人都是妖i 提交于 2019-12-05 07:08:41

问题


Problem: rendering barcodes in CodeIgniter via Zend library barcode.

I googled, and also tried all tutorials on first 2 pages. I stackoverflowed and found quiet a few topics on my problem, even few are marked as answered but no luck.

Finally I tried this https://stackoverflow.com/a/15480779/1564365 but yet another error message.

error:

Fatal error: Class 'Zend\Barcode\ObjectPluginManager' not found

that means it is actually loading Barcode library but with error.

sidenote: ZF 2.2 fresh download (today), CI 2.1.3 fresh download (today)


回答1:


To solve this, I am forced to use ZF1. step by step:

  1. Download (Zend Framework 1.12.3 Full) from here
  2. Unzip files and locate folder Zend in ./libraries folder copy it to CI application/libraries
  3. Create new file inside (CI) application/libraries/Zend.php "loader for ZF"

with code as follows

<?php if (!defined('BASEPATH')) {exit('No direct script access allowed');}

/**
 * Zend Framework Loader
 *
 * Put the 'Zend' folder (unpacked from the Zend Framework package, under 'Library')
 * in CI installation's 'application/libraries' folder
 * You can put it elsewhere but remember to alter the script accordingly
 *
 * Usage:
 *   1) $this->load->library('zend', 'Zend/Package/Name');
 *   or
 *   2) $this->load->library('zend');
 *      then $this->zend->load('Zend/Package/Name');
 *
 * * the second usage is useful for autoloading the Zend Framework library
 * * Zend/Package/Name does not need the '.php' at the end
 */
class CI_Zend
{
    /**
     * Constructor
     *
     * @param   string $class class name
     */
    function __construct($class = NULL)
    {
        // include path for Zend Framework
        // alter it accordingly if you have put the 'Zend' folder elsewhere
        ini_set('include_path',
        ini_get('include_path') . PATH_SEPARATOR . APPPATH . 'libraries');

        if ($class)
        {
            require_once (string) $class . EXT;
            log_message('debug', "Zend Class $class Loaded");
        }
        else
        {
            log_message('debug', "Zend Class Initialized");
        }
    }

    /**
     * Zend Class Loader
     *
     * @param   string $class class name
     */
    function load($class)
    {
        require_once (string) $class . EXT;
        log_message('debug', "Zend Class $class Loaded");
    }
}

and controllers method should be as follows

function barcode() {
    $this->load->library('zend');
    $this->zend->load('Zend/Barcode');
    $test = Zend_Barcode::draw('ean8', 'image', array('text' => '1234565'), array());
    var_dump($test);
    imagejpeg($test, 'barcode.jpg', 100);
}


来源:https://stackoverflow.com/questions/17428466/codeigniter-2-zend-2-library-barcode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!