0

我只想要一个操作来打印条形码图像,但我无法在 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

我刚刚获得:“图像无法显示,因为它有错误”(或类似的东西,取决于浏览器)。谢谢!

4

3 回答 3

0

由于. Content-Type_ Zend_Barcode确保您已log_errors打开并配置了日志的有效/可写目标。通过这种方式,您可以检查错误日志,了解您通常会通过浏览器阅读的任何内容。

http://us3.php.net/manual/en/errorfunc.configuration.php#ini.log-errors

于 2010-03-31T19:49:57.867 回答
0

我对您的代码没有任何问题,我在浏览器中调用此网址:http://localhost/index/barcode?barcodeType=code39&text=ZEND (您的代码在 IndexController 中),我收到了正确的图像。

如果我放入<img src="http://localhost/index/barcode?barcodeType=code39&text=ZEND" />视图,我也有图像。

迈克尔

于 2010-04-02T08:04:22.617 回答
0

我知道这现在可能已经过时了,但是当我遇到同样的问题时,我刚刚添加了

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

它就像一个魅力

于 2017-01-11T10:53:59.430 回答