2013-07-02 35 views
1

問題:通過Zend庫條形碼在CodeIgniter中呈現條形碼。CodeIgniter 2 + Zend 2庫條形碼

我用Google搜索了一下,也嘗試了前兩頁的所有教程。我堆疊並找到了一些關於我的問題的話題,甚至很少有人被標記爲回答,但沒有運氣。

最後我試過這個https://stackoverflow.com/a/15480779/1564365但還有一個錯誤信息。

錯誤:

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

,這意味着它實際上是加載條碼庫,但有錯誤。

旁註:ZF 2.2鮮下載(今天),CI 2.1.3新鮮下載(今天)

回答

2

爲了解決這個問題,我不得不使用ZF1。 一步一步:從here

  1. 下載(Zend框架1.12.3全部)
  2. 解壓縮文件,並在文件夾./libraries找到文件夾Zend複製到CI application/libraries
  3. 內創建新文件(CI)application/libraries/Zend.php與代碼 「加載器爲ZF」

如下

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