我使用 zend 库在 codeigniter 中生成条形码。
这是我的控制器:
$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');
这是我的观点:
<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>
但是条形码无法绘制,因为它说"必须向条形码提供文本以显示"。但我已经宣布$barcode的文本是$kd_barang。 它被保存到数据库中,但作为文本,而不是图像。请帮助我。
无论出于何种原因,您都没有获得$barcode
值。我怀疑您发布的观点没有直接关系。
以下代码将在一定程度上验证输入并修复路径问题。
$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