我是CI的新手,我想使用MVC方式的codeigniter从DB中获取数据。 我似乎无法找到任何解决方案。
model:company.php | dbname:company
public function getAllcompany(){
$query = $this->db->get('company');
if($query->num_rows() > 0)
{
return $query->result();
}
return array();
}
view:branch.php
<?php
echo "<pre>", print_r($records), "</pre>";
?>
controller:home.php
public function getCompany(){
$this->load->model('company','', TRUE);
$data['records'] = $this->company->getAllcompany();
$this->load->view('branch', $data);
}
答案 0 :(得分:3)
您必须将模型更改为:
public function getAllcompany(){
$query = $this->db->get('company');
return $query->result();
}
OR
public function getAllcompany(){
$query = $this->db->get('company');
return $query->result_array();
}