Zend Barcode不呈现?在CodeIgniter中 [英] Zend Barcode is not rendered? in CodeIgniter
问题描述
当我包含Zend库并渲染条形码时,我想在我的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
当我在新的codeigniter项目中使用相同的代码和库时,它可以正常工作并成功生成条形码.
when i use same code and libraries in new codeigniter project its works properly and generate barcode successfully.
为什么会这样?
我的代码是:
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());
}
推荐答案
如果您是从这里得到的 https://github.com/desta88/Codeigniter-Barcode-Generator-Zend-Library
If you have got it from here https://github.com/desta88/Codeigniter-Barcode-Generator-Zend-Library
1:在zend库上,从CI_Zend中删除CI
1: On the zend library remove CI from CI_Zend
文件名Zend.php
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
文件名:Zend_c.php//像这样对它进行命名以进行测试.
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());
}
}
工作证明
这篇关于Zend Barcode不呈现?在CodeIgniter中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!