views:

136

answers:

2

hi people, 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!

A: 

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

awgy
thanks, but Zend_Barcode sets the Content-type correctly to image/png as you can see in http://online.cooprc.com.ar/facturas/codigo/factura/0001-01249361/para/PF, but this seems to happen only in the MVC, because calling this single line: "Zend_Barcode::render($_GET['barcodeType'], 'image', $_GET, $_GET);" in a file in the public folder works like a charm... as you can see in http://online.cooprc.com.ar/barcode.php?text=90000101249361.Thanks!
Joaquín L. Robles
Did you verify your error output settings? I mentioned that the `Content-Type was` set by `Zend_Barcode`, which means the browser is going to expect image data. If PHP sends a string error message to the browser, the browser will consider it to be a corrupt image (which will cause the message you mentioned in your question), since it's expecting an image (based on the `Content-Type`) and not string data.You can correct this by telling PHP not to display errors but to log them to a file instead. This way you can figure out what's going on. (See links above in my original answer)
awgy
A: 

Hi,

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&amp;text=ZEND" /> in a view, I have also the image.

Mickael

mikaelkael