MVC中的zend_barcode

MVC中的zend_barcode

问题描述:

i just want an Action to print a barcode image, but i can´t get this working in MVC, i just do the following:

public function barcodeAction() {
    $this->_helper->layout->disableLayout();
    $this->_helper->viewRenderer->setNoRender();
    Zend_Barcode::render($_GET['barcodeType'], 'image', $_GET, $_GET);
}

but when I call

/barcode?barcodeType=code39&text=ZEND-FRAMEWORK

I just obtain: "The image couldn't be displayed because it has errors" (or something like that, browser-dependant). Thanks!

You're likely getting an error that you can't see due to the Content-Type header that's sent by Zend_Barcode. Make sure you have log_errors turned on and a valid/writeable destination for the log configured. This way you can check the error log for anything that you normally would have read through your browser.

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

I have no problem with your code, I call this url: http://localhost/index/barcode?barcodeType=code39&text=ZEND in my browser (your code is in the IndexController) and I receive the correct image.

If I put <img src="http://localhost/index/barcode?barcodeType=code39&text=ZEND" /> in a view, I have also the image.

Mickael

I know this may be outdated now but when I had the same problem I just added

ob_clean();

in my controller so now my action looks like this

public function generateBarcodeAction() {
    ob_clean();
    $number = $this->params()->fromRoute('number');
    $barcodeOptions = array('text' => $number);
    $rendererOptions = array('imageType'=>'png');
    Barcode::render(
            'ean13', 'image', $barcodeOptions, $rendererOptions
    );
}

and it's working like a charm