1

问题:通过 Zend 库条形码在 CodeIgniter 中呈现条形码。

我用谷歌搜索,还尝试了前 2 页上的所有教程。我在stackoverflow上发现了一些关于我的问题的安静话题,甚至很少有人被标记为已回答,但没有运气。

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

错误:

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

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

旁注:ZF 2.2 新鲜下载(今天),CI 2.1.3 新鲜下载(今天)

4

1 回答 1

2

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

  1. 从这里下载(Zend Framework 1.12.3 Full)
  2. Zend解压缩文件并在文件夹中找到文件./libraries夹,将其复制到 CIapplication/libraries
  3. 在(CI)application/libraries/Zend.php“ZF loader”中创建新文件

代码如下

<?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);
}
于 2013-07-04T08:24:35.087 回答