douping7975 2018-08-09 23:00
浏览 91
已采纳

在使用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.

展开全部

  • 写回答

1条回答 默认 最新

  • dongyu2764 2018-08-09 23:35
    关注

    For whatever reason you aren't getting the $barcode value. I suspect the view you posted isn't directly related.

    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
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
编辑
预览

报告相同问题?

悬赏问题

  • ¥15 PADS Logic 原理图
  • ¥15 PADS Logic 图标
  • ¥15 电脑和power bi环境都是英文如何将日期层次结构转换成英文
  • ¥20 气象站点数据求取中~
  • ¥15 如何获取APP内弹出的网址链接
  • ¥15 wifi 图标不见了 不知道怎么办 上不了网 变成小地球了