Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
745 views
in Technique[技术] by (71.8m points)

php - Zend Barcode is not rendered? in CodeIgniter

i want to generate barcode in my codeigniter application, when i include Zend libraries and rendered barcode its not rendered and its give error that

The image ...cannot displayed its contain errors

when i use same code and libraries in new codeigniter project its works properly and generate barcode successfully.

Why this happens?

My code is:

function gen_barcode()
{
       //I'm just using rand() function for data example
        $temp = rand(10000, 99999);
        $this->set_barcode($temp);
}
private function set_barcode($code)
{
    //load library
    $this->load->library('zend');
    //load in folder Zend
    $this->zend->load('Zend/Barcode');
    ////generate barcode
    Zend_Barcode::render('code128', 'image', array('text'=>$code), array());
}
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

If you have got it from here https://github.com/desta88/Codeigniter-Barcode-Generator-Zend-Library

1: On the zend library remove CI from CI_Zend

Filename Zend.php

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

class Zend { // remove CI_

public function __construct($class = NULL)
{
    ini_set('include_path',
    ini_get('include_path'). PATH_SEPARATOR. APPPATH. 'libraries');

    if($class)
    {
        require_once(string) $class.'.php'; //fixed CI 3 issue by lilsammy
        log_message('debug', "Zend Class $class Loaded");
    }else
    {
        log_message('debug', "Zend Class Initialized");
    }
}

public function load($class)
{
    require_once(string) $class.'.php'; //fixed CI 3 issue by lilsammy
    log_message('debug', "Zend Class $class Loaded");
}

}

Then on the controller should look something like

Filename: Zend_c.php // Just named it like that for testing.

<?php

class Zend_c extends CI_Controller {

    public function __construct() {
        parent::__construct();
        $this->load->library('zend');
        $this->zend->load('zend/barcode');
    }

    public function index() {
        $temp = rand(10000, 99999);
        echo $this->set_barcode($temp);
    }

    private function set_barcode($code)
    {
        return Zend_Barcode::render('code128', 'image', array('text'=>$code), array());
    }
}

Working Proof

enter image description here


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...