I use zend libraries to generate barcode in codeigniter.
This is my controller :
$this->load->library('zend');
$this->zend->load('Zend/Barcode');
$barcode = $this->input->post('barcode'); //nomor id barcode
$imageResource = Zend_Barcode::factory('code128', 'image', array('text'=>$barcode), array())->render();
$imageName = $barcode.'.jpg';
$imagePath = 'barcode/'; // penyimpanan file barcode
imagejpeg($imageResource, $imagePath.$imageName);
$pathBarcode = $imagePath.$imageName;
$kd_barang = $this->input->post('kd_barang');
$pathBarcode = $this->input->post('barcode');
$editdata=array(
/*Nama Field => $Nama Variabel*/
'barcode' => $pathBarcode
);
/*Primary Key Sebagai Kunci*/
$where=array(
'kd_barang'=>$kd_barang
);
/*Mengambil Function Dari Model*/
$this->m_operator->aksi_update_barang($where,$editdata,'barang');
redirect('c_op/index');
This is my view :
<form action="<?php echo base_url(). 'index.php/c_op/aksi_editbarang'; ?>" method="post">
<center>
<table border="1">
<?php
foreach ($edit->result() as $c){?>
<tr>
<td>Kode Barang</td>
<!-- Primary Key Sebagai Kunci -->
<td><input type="text" name="kd_barang" value="<?php echo $c->kd_barang ?>" readonly></input></td>
<tr>
<td>Barcode</td>
<td><input type="text" name="barcode" value="<?php echo $c->kd_barang ?>" readonly><?php echo $c->barcode;?></td>
</tr>
<tr>
<td><button type="submit">UPDATE</button></td>
</tr>
<?php } ?>
</table>
</center>
</form>
But the barcode could not be drawn because it said "A text must be provide to Barcode befeore drawing". But i have already declare that the text for $barcode is $kd_barang. It's saved to the database but as a text, not as image. Please help me.