生成非功能数据表

时间:2016-10-10 12:09:21

标签: model-view-controller datatables codeigniter-3

我一直在尝试使用我的codeigniter应用程序中的数据表中的数据库获取输出。我已经遵循了所有形式的方法,但不知何故,生成的数据表只是一个静态的非响应表。我正在粘贴下面的代码。

这是我的控制者:

<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Datatable_Control extends CI_Controller 
{
public function __construct()
{
    parent::__construct();

}

public function index()
{


//  $this->load->helper('url');
    $this->load->model('order_dt');

    $customer_list = $this->order_dt->getAllCustomers();
    $data["customers_list"] = $customer_list;
    $this->load->view("datatable", $data); 
}

}

?>

这是我的模特:

<?php

class Order_dt extends CI_Model {

    public function getAllCustomers(){

        $this->load->database();

           $query = $this->db->get('customers');
    return $query->result(); 
    }
}

?>

这是我的观点:

<!DOCTYPE html>
<meta charset="UTF-8">

<head>  
<script type="text/javascript" language="javascript"

src="//code.jquery.com/jquery-1.11.1.min.js"></script>


<script type="text/javascript" language="javascript" 
    src="//cdn.datatables.net/1.10.4/js/jquery.dataTables.min.js"></script>
<link rel="stylesheet" type="text/css" 

href="//cdn.datatables.net/1.10.4/css/jquery.dataTables.css">

<script language="javascript" type="text/javascript">

$(document).ready(function () {
    $('#rahul').DataTable();
});
</script>

</head>

<body>

 <div class="page-header">
   <h1>CI-DataTables Library Example</h1>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="panel panel-default">
          <div class="panel-body">
                <table id="rahul">
                    <thead>
                        <tr>
                            <td><strong>Customer Number</strong></td>
                            <td><strong>Last Name</strong></td>
                            <td><strong>First Name</strong></td>
                            <td><strong>Phone</strong></td>
                            <td><strong>Address 1</strong></td>
                            <td><strong>Address 2</strong></td>
                            <td><strong>City</strong></td>
                            <td><strong>State</strong></td>
                            <td><strong>Postal Code</strong></td>
                            <td><strong>Country</strong></td>
                            <td><strong>Sales Emp No.</strong></td>
                            <td><strong>Credit Limit</strong></td>
                        </tr>
                        <?php foreach ($customers_list as $c): ?>
                        <tr>
                             <td><?php echo $c->customerNumber; ?></td>
                             <td><?php echo $c->customerName; ?></td>
                             <td><?php echo $c->contactLastName; ?></td>
                             <td><?php echo $c->contactFirstName; ?></td> 
                             <td><?php echo $c->phone; ?></td>
                             <td><?php echo $c->addressLine1; ?></td>
                             <td><?php echo $c->addressLine2; ?></td>
                             <td><?php echo $c->city; ?></td> 
                             <td><?php echo $c->state; ?></td>
                             <td><?php echo $c->postalCode; ?></td>
                             <td><?php echo $c->country; ?></td>
                         <td><?php echo $c->salesRepEmployeeNumber; ?> 

  </td>
                             <td><?php echo $c->creditLimit; ?></td>
                        </tr>

                        <?php endforeach ?>
                    </thead>
                    <tbody></tbody>
                </table>
          </div>

        </div>
    </div>
</div>
</body>

</html>

我尝试并搜索了所有可能的方法来获得功能正常的数据表。我无法找出我的代码有什么问题或我错过了什么。请指导。我附上一张图片: enter image description here

1 个答案:

答案 0 :(得分:0)

这个问题很愚蠢。我正在使用<tbody>标记中的表格数据。