我在CodeIgniter-2.2.1中不断收到此错误.(致命错误:在第6行的C:\ xampp\htdocs\ci\application\models\site_model.php中调用null上的成员函数get())我不是确定为什么会这样.我正确地调用了这个函数吗?第6行是$ this-> load-> model('site_model');
控制器site.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);
}}
Run Code Online (Sandbox Code Playgroud)
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;
}
}
}
?>
Run Code Online (Sandbox Code Playgroud)
home.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>
Run Code Online (Sandbox Code Playgroud)