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

[eluser]kyleb[/eluser]
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:

http://codeigniter.com/tutorials/watch/blog/

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:
Code:
<?php

class Visits extends Controller {

    function Visits()
    {
        parent::Controller();

    }

    function index()
    {

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

And my view code looks like this:

Code:
<h1>&lt;?=$heading?&gt;</h1>

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

<h3>&lt;?=$row->title?&gt;</h3>

&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:
Code:
SELECT * FROM VISIT LIMIT 20, 10
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