2013-03-18 19 views
0

我需要顯示(以及稍後打印)帶有包含條形碼和每行描述的表格的頁面。使用zend獲取帶有條形碼的表格

我有我的包含正確的數據

$result = $mySql->query->fetchAll(); 

起初我用壞的結果做出了

$rendererOptions = array(); 
    foreach($result as &$res){ 
     $barcodeOptions = array(
       'text' => $res['myParam'], 
       'rendererParams' => array('imageType' => 'gif'),); 
     $res['barcode'] = Zend_Barcode::factory('CODE39', 'image', $barcodeOptions, $rendererOptions)->draw(); 
} 

    $this->view->data = $result; 

。然後我試着用:

Zend_Barcode::render(....); 

有許多組合,甚至

$.post('/mycontroller/myactionthatrendersthebarcode',{code : this.id}, function(data){ 
      $(this).html(data);  }); 
我一個.phtml頁

(幾乎查殺網絡:d)

繼文檔(http://framework.zend.com/manual/1.12/en/zend.barcode.creation.html) 我只有一個,但正確的,條形碼或一堆資源我不知道如何管理。

有什麼建議嗎? 謝謝

+0

什麼意思是壞結果?你會得到一個異常/錯誤? – bitWorking 2013-03-18 13:49:08

+0

沒有簡單的一個損壞的圖像標誌或根本沒有結果。 我理解的唯一事情是我錯過了「邏輯方法」來做到這一點...... – mauoftheclouds 2013-03-18 14:03:11

回答

0

draw方法返回一個gd圖像資源。要輸出的圖像,你可以這樣做:

$rendererOptions = array(); 
$barcodeOptions = array(
    'text' => 'TEST', 
    'rendererParams' => array('imageType' => 'gif'), 
); 
$resource = Zend_Barcode::factory('CODE39', 'image', $barcodeOptions, $rendererOptions)->draw(); 

header('Content-Type: image/gif'); 
imagegif($resource); 
exit; 

render方法自動爲您做到這一點:

$rendererOptions = array(); 
$barcodeOptions = array(
    'text' => 'TEST', 
    'rendererParams' => array('imageType' => 'gif'), 
); 
Zend_Barcode::factory('CODE39', 'image', $barcodeOptions, $rendererOptions)->render(); 
exit; 

如果你想輸出的img標籤的圖像,你必須寫上述成行動並稱之爲。因此,例如上面的腳本是outputActionImgController

<img src="/img/output"> 

如果你想讓它動態,您可以發送得到PARAMS的動作和做邏輯的行動。

<img src="/img/output/text/TEXT"> 
<img src="/img/output/id/123"> 
+0

非常感謝!它完美的工作! – mauoftheclouds 2013-03-18 16:51:05

相關問題