致命错误:在第6行调用C:\wamp\www\ci\application\models\site_model.php中的非对象的成员函数get() [英] Fatal error: Call to a member function get() on a non-object in C:\wamp\www\ci\application\models\site_model.php on line 6
问题描述
你好,我只是看了第一个/ Day1屏幕录像在NettutsCodeIgniter从scracth我已经遇到一个错误,我不明白。以下是屏幕截图 http://i39.tinypic.com/14mtc0n.jpg
Hello I just watched the first/Day1 screencast on Nettuts "CodeIgniter from scracth" And I'm already running into an error I don't understand. Here's a screenshot http://i39.tinypic.com/14mtc0n.jpg
我的models\site_model.php中的代码与screencast相同
The code in my models\site_model.php is the same as the screencast
models\site_model.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;
}
}
并且控制器controllers\site.php
And the controller controllers\site.php
class Site extends CI_Controller {
function index(){
$this-> load-> model('site_model');
$data['records'] = $this-> site_model-> getAll();
$this-> load-> view('home', $data);
}
}
/ p>
And here's my db info incase
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'ci_series';
(rest is default below)
谢谢
推荐答案
您需要首先加载数据库。 Codeiginiter将不会默认为您加载。
You need to load the database first. Codeiginiter won't load it by default for you.
您可以将其添加到 /config/autoload.php
like like
You can either add it to /config/autoload.php
like so
$autoload['libraries'] = array('database');
或者您可以通过调用
$this->load->database();
更多详情
http://codeigniter.com/user_guide/database/connecting.html
这篇关于致命错误:在第6行调用C:\wamp\www\ci\application\models\site_model.php中的非对象的成员函数get()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!