【问题标题】:Zend Barcode is not rendered? in CodeIgniterZend Barcode 不渲染?在 CodeIgniter 中
【发布时间】:2017-02-27 23:19:36
【问题描述】:

我想在我的 codeigniter 应用程序中生成条形码,当我包含 Zend 库并渲染条形码时,它没有渲染并且它给出错误

图像...无法显示其包含错误

当我在新的 codeigniter 项目中使用相同的代码和库时,它可以正常工作并成功生成条形码。

为什么会这样?

我的代码是:

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

【问题讨论】:

    标签: php codeigniter zend-framework barcode


    【解决方案1】:

    如果你从这里得到它https://github.com/desta88/Codeigniter-Barcode-Generator-Zend-Library

    1:在 zend 库中,从 CI_Zend 中移除 CI

    文件名 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");
    }
    
    }
    

    然后在控制器上应该看起来像

    Filename: Zend_c.php // 只是为了测试而命名它。

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

    工作证明

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-05-24
      • 1970-01-01
      • 1970-01-01
      • 2012-09-04
      • 1970-01-01
      • 1970-01-01
      • 2011-06-18
      相关资源
      最近更新 更多