douping7975 2018-08-10 07: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-10 07: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 救!ENVI5.6深度学习初始化模型报错怎么办?
  • ¥30 eclipse开启服务后,网页无法打开
  • ¥30 雷达辐射源信号参考模型
  • ¥15 html+css+js如何实现这样子的效果?
  • ¥15 STM32单片机自主设计
  • ¥15 如何在node.js中或者java中给wav格式的音频编码成sil格式呢
  • ¥15 不小心不正规的开发公司导致不给我们y码,
  • ¥15 我的代码无法在vc++中运行呀,错误很多
  • ¥50 求一个win系统下运行的可自动抓取arm64架构deb安装包和其依赖包的软件。
  • ¥60 fail to initialize keyboard hotkeys through kernel.0000000000