我只是想要一个操作来打印条形码图像,但我不能让这在MVC中工作,我只是做了以下:
public function barcodeAction() {
$this->_helper->layout->disableLayout();
$this->_helper->viewRenderer->setNoRender();
Zend_Barcode::render($_GET['barcodeType'], 'image', $_GET, $_GET);
}但是当我打电话给
/barcode?barcodeType=code39&text=ZEND-FRAMEWORK我只是得到了:“图像无法显示,因为它有错误”(或者类似的东西,依赖于浏览器)。谢谢!
发布于 2010-04-01 03:49:58
您可能会收到一个由于Zend_Barcode发送的Content-Type头而看不到的错误。确保您打开了log_errors,并且为日志配置了一个有效/可写的目标。通过这种方式,您可以检查错误日志中通常通过浏览器读取的任何内容。
http://us3.php.net/manual/en/errorfunc.configuration.php#ini.log-errors
发布于 2010-04-02 16:04:23
我对您的代码没有问题,我在我的浏览器中调用了这个url:http://localhost/index/barcode?barcodeType=code39&text=ZEND (您的代码在IndexController中),并且我收到了正确的图像。
如果我将<img src="http://localhost/index/barcode?barcodeType=code39&text=ZEND" />放在一个视图中,我也会得到图像。
米克尔
发布于 2017-01-11 18:53:59
我知道这可能已经过时了,但当我遇到同样的问题时,我只是添加了
ob_clean();在我的控制器中,所以现在我的操作如下所示
public function generateBarcodeAction() {
ob_clean();
$number = $this->params()->fromRoute('number');
$barcodeOptions = array('text' => $number);
$rendererOptions = array('imageType'=>'png');
Barcode::render(
'ean13', 'image', $barcodeOptions, $rendererOptions
);
}它的效果就像一个护身符
https://stackoverflow.com/questions/2555201
复制相似问题