Welcome Guest, Not a member yet? Register   Sign In
Tutorial problems: "Call to a member function on a non-object"

Hey everyone,

I'm new to CI and the MVC structure, but I am looking forward to developing with it! I am following the excellent tutorials here:


And I'm having a bit of a problem loading any information from the database. I am using a pre-existing DB that I can connect to just fine (I have read-only access), scaffolding works, and I've done part one of the tutorial.

My controller code looks like this:

class Visits extends Controller {

    function Visits()


    function index()

        $data['title'] = "CodeIgniter Testing";
        $data['heading'] = "Testing Visit Table Access";
        $data['query'] = $this->db->get('VISIT');

And my view code looks like this:


&lt;?php foreach($query->result() as $row): ?&gt;


&lt;?php endforeach; ?&gt;

My problem is that when I attempt to view it at /index.php/visits, I get the following error:

"Fatal error: Call to a member function on a non-object in ...../codeigniter/system/application/controllers/visits.php on line 16

Line 16, of course, is:

$data['query'] = $this->db->get('VISIT');

I've quadruple checked it and Googled around - my code is identical to the screencast tutorial, yet it does not work at all. I am running some instance of PHP 4.x, though I don't think that matters.

The table name is in all caps (yes, I know - I'm not the DBA, I don't control these things) and I assure you it exists, as:
Works just fine when I query the DB directly using SQLyog.

Thanks in advance! I know it's something small...

Messages In This Thread
Tutorial problems: "Call to a member function on a non-object" - by El Forum - 12-21-2009, 07:52 PM

Theme © iAndrew 2016 - Forum software by © MyBB