title: codeigniter model error: Undefined property
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/13964398/error-get-property-of-non-object">Error : get property of non-object</a>  </p>
  </blockquote>
  
  
  
  <p>I am new to codeigniter model, i try to follow steps in docs to load all user registered in my db.</p>
  
  <p>This is my model: <code>user.php</code></p>
  
  <pre><code>class User extends Model {
       function user() {
           parent::Model();
       }
       function alluser() {
           $query = $this-&gt;db-&gt;query("select * from user limit 0,5"); //Line 30 error as in my IDE located in this line
           return $query-&gt;result();
       }
  }
  </code></pre>
  
  <p>This is my controller: <code>home.php</code></p>
  
  <pre><code>class home extends Controller {
  
  function index() {
  
      parent::Controller();
  
  }
  function alluser() {
      $this-&gt;load-&gt;model('User');
      $result = $this-&gt;User-&gt;showusers();
      if ($result-&gt;num_rows()&gt;0) {
          foreach ($result as $row) {
              echo "ID:".$row-&gt;userid." ".$row-&gt;userpenname."&lt;br /&gt;";
              echo $row-&gt;userfirstname." ".$row-&gt;userlastname."&lt;br /&gt;";
          }
        }
     }
  }
  </code></pre>
  
  <p>it showing error:</p>
  
  <pre><code>A PHP Error was encountered
  
  Severity: Notice
  
  Message: Undefined property: User::$db
  
  Filename: models/user.php
  
  Line Number: 30
  </code></pre>
  
  <blockquote>
    <p>Fatal error: Call to a member function query() on a non-object in <br>G:\xampp\htdocs\fiksi\system\application\models\user.php on line 30</p>
  </blockquote>
  
  <p>Line 30 see comment above...</p>