我需要在Codeigniter的HTML表库中正确循环客户名称,但我不知道如何正确使用它。
所以,这是我的模特:
<?php class Dash_model extends CI_Model {
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function customerlist()
{
$query = $this->db->query("SELECT customername FROM customertable ORDER BY customerid");
foreach ($query->result() as $row)
{
echo $row->customers;
}
}
然后这是我的控制器:
class Dash_control extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('dash_model');
$this->load->library('table');
}
public function index()
{
$tmpl = array (
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
);
$this->table->set_template($tmpl);
$data['customerloop'] = $this->dash_model->customerlist();
$this->load->view('dashboard',$data);
}
在此之后代码工作正常,我可以循环客户名称,但我不知道如何将它们传递到我的视图文件中。我正在使用引导程序表,所以我认为我可以使用它:
<tbody>
<td><?php echo $customerloop;?></td>
</tbody>
但当然它在表格中不起作用,它只是像没有表格那样循环。
还有一个问题,Codeigniter的表在Bootstrap中有效吗?或者它已经响应没有引导程序?我对Codeigniter很新,所以谢谢你给我的每一个建议......
答案 0 :(得分:1)
您可以在视图页面中使用html表类
<table border="1" class="table table-bordered table-hover dataTable">
<tr role="row">
<th class="sorting" width="5%">Customer data</th>
<?php
foreach ($customerloop as $row) {
?><tr>
<td class=" "><?php echo $row->data; ?></td>
</tr>
<?php }
?>
</table>
答案 1 :(得分:0)
型号:
public function __construct()
{
parent::__construct();
$this->load->database();
}
public function customerlist()
{
$query = $this->db->query("SELECT customername FROM customertable ORDER BY customerid");
return $query->result();
}
控制器:
class Dash_control extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('dash_model');
$this->load->library('table');
}
public function index()
{
$tmpl = array (
'row_start' => '<tr>',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
);
$this->table->set_template($tmpl);
$data['customerloop'] = $this->dash_model->customerlist();
$this->load->view('dashboard',$data);
}
查看:
<tbody>
<?php foreach ($customerloop as $row)
{ ?>
<tr><td><?php echo $row->customers; ?></td></tr>
<?php } ?>
</tbody>