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

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

Model
Code:
class Articles_model extends Model
{
  function Articles_model()
  {
    parent::Model();
  }

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

Controller
Code:
$this->load->model('Articles_model');
    $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)
Code:
$CI = get_instance();
    
    $CI->load->model('Articles_model');
    $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!


Messages In This Thread
Getting the following message: Using $this when not in object context in - by El Forum - 08-07-2007, 09:53 AM



Theme © iAndrew 2016 - Forum software by © MyBB