【发布时间】:2014-05-09 02:50:30
【问题描述】:
问题出在这里:CodeIgniter 从控制器加载数据,而不是从视图加载数据
当我转到页面的源并单击表单操作链接时,它会在源代码中而不是在 html 视图中加载数据。
--查看
<table class="table hovered">
<thead>
<tr>
<th class="text-left">User ID</th>
<th class="text-left">Type</th>
<th class="text-left">Name</th>
<th class="text-left">Email</th>
<th class="text-left">Phone</th>
</tr>
</thead>
<tbody>
<?php echo form_open('admin/manage_customer') ?><!-- start of the form -->
<?php if(isset($records)) : foreach($records as $row) : ?>
<tr>
<td class="right"><?php echo $row->cus_id; ?></td>
<td class="right">Admin</td>
<td class="right"><?php echo $row->cus_name; ?></td>
<td class="right"><?php echo $row->cus_email; ?></td>
<td class="right"><?php echo $row->cus_phone; ?></td>
</tr>
<?php endforeach; ?>
<?php endif; ?>
<?php echo form_close(); ?><!-- END of the form -->
</tbody>
<tfoot></tfoot>
</table>
---控制器
function inbox()
{
$data = array();
if($query = $this->mod_contactus->get_records())
{
$data['records'] = $query;
}
$this->load->view('admin/admin_messages',$data);
}
---型号
<?php
class Mod_contactus extends CI_Model //Users (model name) share all the class and functions CodeIgniter models have
{
function get_records()
{
$query = $this->db->get('tbl_contactus');
return $query->result();
}
function add_record($data)
{
$this->db->insert('tbl_contactus', $data);
return;
}
function update_record()
{
}
}
【问题讨论】:
-
您是否在视图中尝试过 var_dump($records) 或 print_r($records)?试试看。如果它正在转储数据,那么它可能是一个 html 结构问题。
-
是的,我尝试了 var_dump($records) 但没有任何结果
-
这似乎是这个问题的副本。 stackoverflow.com/questions/23531777/… 相同的行动方案可以纠正这个问题吗?
标签: php codeigniter