CodeIgniter 2 + Zend 2库条形码

时间:2013-07-02 14:37:42

标签: php zend-framework2 codeigniter-2 barcode

问题:通过Zend库条形码在CodeIgniter中渲染条形码。

我用Google搜索,并在前两页尝试了所有教程。我堆栈溢出,发现我的问题安静了几个主题,甚至很少被标记为已回答,但没有运气。

最后我尝试了这个https://stackoverflow.com/a/15480779/1564365,但又发现了另一条错误消息。

错误:

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

这意味着它实际上正在加载条形码库但有错误。

旁注:ZF 2.2全新下载(今日),CI 2.1.3全新下载(今日)

1 个答案:

答案 0 :(得分:2)

为了解决这个问题,我被迫使用ZF1。 一步一步:

  1. here
  2. 下载(Zend Framework 1.12.3 Full)
  3. 解压缩文件并找到Zend文件夹中的文件夹./libraries,将其复制到CI application/libraries
  4. 在(CI)application/libraries/Zend.php“ZF加载程序”
  5. 中创建新文件

    代码如下

    <?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");
        }
    }
    

    和控制器方法应如下

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