我在CodeIgniter-2.2.1.(致命错误:在第 6 行的 C:''xampp''htdocs''ci''application''models''site_model.php 中调用成员函数 get() 我不确定为什么会发生这种情况。我是否正确调用了函数?第 6 行是 $this->负载>模型('site_model');
控制器站点.php
<?php
class Site extends CI_Controller{
function index(){
$this->load->model('site_model');
$data['records'] = $this->site_model->getAll();
$this->load->view('home', $data);
}}
site_model.php
<?php
class Site_model extends CI_Model{
function getAll(){
$q = $this->db->get('test');
if($q->num_rows() >0){
foreach ($q->result() as $row)
{
$data[] =$row;
}
return $data;
}
}
}
?>
首页.php 查看页面
<!DOCTYPE>
<html>
<head>
<title>Site</title>
</head>
<body>
<div id="container">
<p>My view has been loaded</p>
<pre>
<?php print_r($records);?>
</pre>
</body>
</html>
您是否正在加载数据库
$this->load->database();