在Codeigniter数据表中显示图像

时间:2018-11-28 13:58:03

标签: ajax datatables codeigniter-3

控制器::此处productlist2()只需调用视图页面。

function productlist2()
    {
        $this->load->view("admin/bill/datatable.php", array());
    }

 public function productlist_page()
    {    
        $draw = intval($this->input->get("draw"));
        $start = intval($this->input->get("start"));
        $length = intval($this->input->get("length"));
        $books = $this->Category_model->get_all_product_datatable();
        $data = array();
        foreach($books->result() as $r) {
            $data[] = array(
                $r->categoryID,
                $r->productName,
                $r->costPrice,
                $r->salesPrice,
                $r->unit,
                $r->origin,
                $r->files
            );
        }
        $output = array(
            "draw" => $draw,
            "recordsTotal" => $books->num_rows(),
            "recordsFiltered" => $books->num_rows(),
            "data" => $data
        );
        echo json_encode($output);
        exit();
    }

ajax调用productlist_page()函数后,此productlist_page()从模型中获取值。 查看:

<table id="book-table" class="table table-bordered table-striped table-hover">
                        <thead>
                        <tr>
                            <td>ID</td>
                            <td>Product Name</td>
                            <td>Cost Price</td>
                            <td>Sales Price</td>
                            <td>Unit</td>
                            <td>Description</td>
                            <td>Picture</td>        
                        </tr>
                        </thead>
                    <tbody>     
                   </tbody>

               </table>

这是我的js脚本代码。

<script type="text/javascript">
               $(document).ready(function() {
                   $('#book-table').DataTable({
                       "ajax": {
                           url : "<?php echo site_url("admin/category/productlist_page") ?>",
                           type : 'GET'
                       },

                   });
               });
        </script>

在这里,我要在图片列中显示图像,只有字符串值作为文件列中的输出存在。问题是如何显示图像?

0 个答案:

没有答案