Welcome Guest, Not a member yet? Register   Sign In
Getting the following message: Using $this when not in object context in

Good morning,

I finally got my Apache/PHP/Mysql woes straightened out and I am trying to get cracking on this app I need to create, and I'm hitting a stumbling block. All that my code is doing right now is querying a table, getting the data and then passing it to my view. The code looks like this:

class Articles_model extends Model
  function Articles_model()

  function list_articles()
    $query = $this->db->query("SELECT * FROM articles");
    return $query;

    $data['query'] = $this->Articles_model->list_articles();
    $this->load->view('articles', $data);

When I attempt to access the page it tells me:
Fatal error: Using $this when not in object context in /var/www/dev/dsn/system/application/controllers/articles.php on line 2

I've tried to use the following code (researched from the various helper threads)
$CI = get_instance();
    $data['query'] = $CI->Articles_model->list_articles();
    $CI->load->view('articles', $data);

But then I get this message instead:
Severity: Notice

Message: Trying to get property of non-object

Filename: controllers/articles.php

Line Number: 4

Fatal error: Call to a member function model() on a non-object in /var/www/dev/dsn/system/application/controllers/articles.php on line 4

Any help is appreciated, as right now I can't even get CI to return the data I need. Also keep in mind that I'm a CI newb, though I am trying!

Bleh, nevermind. I was leaving out my class call. Duh. Sorry for the trouble.

Theme © iAndrew 2016 - Forum software by © MyBB