所以我不知道这是我的控制器还是CodeIgniter Framework中的模型出了什么问题,请提供帮助。我的表在我的视图中没有从数据库中获取数据。
我已经尝试了我在stackoverflow中看到的所有内容,但是我无法使其正常工作,但这是我的原始代码。
这是我的控制器:
public function index(){
$data['suppliers'] = $this->dashboard_model->readSupplier();
$data['items'] = $this->dashboard_model->readItem();
$data['users'] = $this->dashboard_model->readUser();
$data['units'] = $this->dashboard_model->readUnit();
$data['logs'] = $this->dashboard_model->readLogs();
$this->global['pageTitle'] = 'Dashboard';
$this->loadViews("pages/dashboard",$this->global,$data);
这是我的模型:
class Dashboard_model extends CI_Model{
function readSupplier(){
$this->db->from('suppliers');
$this->db->limit(5);
$this->db->order_by('supplier_id','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readItem(){
$data = array(
'categories.category_name','items.item_id','items.category_id','items.brand_name','items.model','items.serial','items.unit_price','items.status','items.location_id','suppliers.supplier_id','suppliers.supplier_name'
);
$this->db->select($data);
$this->db->from('items');
$this->db->join('categories','categories.category_id =
items.category_id','left');
$this->db->join('suppliers','suppliers.supplier_id =
items.supplier_id','left');
$this->db->limit(10);
$this->db->order_by('item_id','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readUser(){
$this->db->from('users');
$this->db->limit(10);
$this->db->order_by('userId','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readUnit(){
$data = array(
'l.location_name','su.su_id','su.unit','su.motherboard','su.processor','su.ram','su.hdd','su.video_card','su.lan_card','su.power_supply','su.location_id','su.comment',);
$this->db->select($data);
$this->db->from('system_unit as su');
$this->db->join('locations as l','l.location_id=su.location_id','left');
$this->db->limit(10);
$this->db->order_by('unit','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
function readLogs(){
$this->db->from('activities as a');
$this->db->join('users as u','u.userId=a.userId','left');
$this->db->limit(10);
$this->db->order_by('userId','DESC');
$query = $this->db->get();
$result = $query->result();
return $result;
}
?>
这是我的视图:
<th>User ID</th>
<th>Full Name</th>
<th>Email</th>
</thead>
<tbody>
<?php
if(!empty($users)):
foreach($users as $user): ?>
<tr>
<td><?php echo $user->userId; ?></td>
<td><?php echo $user->firstname." ".$user->lastname; ?></td>
<td><?php echo $user->email; ?></td>
</tr>
<?php endforeach;
endif;
?>