A text must be provide to Barcode before drawing in codeigniter

Clash Royale CLAN TAG#URR8PPP
A text must be provide to Barcode before drawing in codeigniter
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.
var_dump($barcode);
i deleted the redirect and replace it with var_dump($pathBarcode), the image show up , but not saved to the database
– Akmal Athallah
Aug 10 at 7:15
so your problem is no longer: "A text must be provide to Barcode befeore drawing"
– Alex
Aug 10 at 7:17
but i open the image path on folder barcode, the image is still said a text must be provide to barcode before drawing
– Akmal Athallah
Aug 10 at 7:21
so again I must ask var_dump($barcode); what is it?
– Alex
Aug 10 at 7:22
1 Answer
1
For whatever reason you aren't getting the $barcode value. I suspect the view you posted isn't directly related.
$barcode
The following code will validate input to some degree and fix the path issue.
$this->load->library('zend');
$this->zend->load('Zend/Barcode');
$barcode = $this->input->post('barcode'); //nomor id barcode
$kd_barang = $this->input->post('kd_barang');
if (is_null($barcode) || is_null($kd_barang))
show_error('Missing parameters');
// make 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;
$editdata = array(
'barcode' => $pathBarcode
);
$where = array(
'kd_barang' => $kd_barang
);
$this->m_operator->aksi_update_barang($where, $editdata, 'barang');
//redirect('c_op/index'); commented out for debugging
still no image, just a text 'barcode/BA1.jpg'
– Akmal Athallah
Aug 10 at 8:22
wait, you want to store an image in your database rather than the oath? why are you writing it to a file then? is your column a BLOB? what are you trying to accomplish?
– Alex
Aug 10 at 8:27
and the other 3 questions?
– Alex
Aug 10 at 9:03
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
var_dump($barcode);what is it?– Alex
Aug 10 at 7:08