[英]CodeIgniter 2 + Zend 2 library barcode
Problem: rendering barcodes in CodeIgniter via Zend library barcode. 问题:通过Zend库条形码在CodeIgniter中呈现条形码。
I googled, and also tried all tutorials on first 2 pages. 我用谷歌搜索,还尝试了前2页上的所有教程。 I stackoverflowed and found quiet a few topics on my problem, even few are marked as answered but no luck. 我堆栈溢出,发现关于我的问题的一些话题比较安静,甚至没有几个被标记为已回答,但是没有运气。
Finally I tried this https://stackoverflow.com/a/15480779/1564365 but yet another error message. 最后,我尝试了此https://stackoverflow.com/a/15480779/1564365,但又出现了一条错误消息。
error: 错误:
Fatal error: Class 'Zend\\Barcode\\ObjectPluginManager' not found
that means it is actually loading Barcode library but with error. 这意味着它实际上正在加载条形码库,但有错误。
sidenote : ZF 2.2 fresh download (today), CI 2.1.3 fresh download (today) 旁注 :ZF 2.2全新下载(今天),CI 2.1.3全新下载(今天)
To solve this, I am forced to use ZF1. 为了解决这个问题,我不得不使用ZF1。 step by step: 一步步:
Zend
in ./libraries
folder copy it to CI application/libraries
解压缩文件并在./libraries
文件夹中找到Zend
文件夹将其复制到CI application/libraries
application/libraries/Zend.php
"loader for ZF" 在(CI) application/libraries/Zend.php
“ ZF加载程序”中创建新文件 with code as follows 与代码如下
<?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");
}
}
and controllers method should be as follows 控制器方法应如下
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.