Search code examples
phpcodeigniterzend-frameworkcodeigniter-2barcode

codeigniter + zend barcode class


I integrated the Zend_Barcode class by placing Zend directory on application/libraries.

Under my controller:

  public function barcode_gen()
  {
    $this->load->library('Zend/Barcode/Barcode');
    $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
    $rendererOptions = array();
    Zend_Barcode::factory('code39', 'image', $barcodeOptions, $rendererOptions)->render();
  }

However, this results into:

Non-existent class: Barcode

I've also read lots of tutorial but never figured out how to, some tuts are quite outdated.

Even if I followed this thread on CI forums, no luck.


Solution

  • When you load an external class using $this->load->library() Codeigniter puts the instance of the class in a variable named like the class loaded, so you need to access that way

    Since you're then calling it statically instead, I suggested dropping the CI loader method and simply include the class:

    public function barcode_gen()
    {
       require_once('./application/libraries/Zend/Barcode/Barcode.php');
       //adjust the above path to the correct location
        $barcodeOptions = array('text' => 'ZEND-FRAMEWORK');
        $rendererOptions = array();
       Zend_Barcode::factory('code39', 'image', $barcodeOptions, $rendererOptions)->render();
    }