调用非对象上的成员函数get() [英] Call to a member function get() on a non-object
本文介绍了调用非对象上的成员函数get()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用Codeigniter框架,我收到以下错误,
I'm using the Codeigniter Framework and I'm getting the following error,
调用成员函数get第11行的site_model.php中的非对象
call to a member function get() on a non-object in site_model.php on line 11
这是get()的行。 test是我的数据库中的表的名称。我做错了什么?
which is the row with the get() . test is the name of my table in my database. What am i doing wrong?
<?php
class Site extends CI_Controller
{
function index()
{
$this->load->model('site_model');
$data['records']= $this->site_model->getAll();
$this->load->view('home',$data);
}
}
?>
<?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;
}
}
推荐答案
最好的猜测是您未设置数据库:
My best guess is you didn't setup your database:
加载模型时不会自动连接您的
数据库。
When a model is loaded it does NOT connect automatically to your database.
请参阅此处的指南: http://ellislab.com/codeigniter/user_guide/general/models.html#conn
这篇关于调用非对象上的成员函数get()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文