CodeIgniter Forums
undefined property - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: undefined property (/thread-53824.html)



undefined property - El Forum - 08-10-2012

[eluser]cerberus478[/eluser]
Hi

I'm using codeigniter 2.1.2 and I'm busy doing a tutorial called codeigniter from scratch but I get an error saying

Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$db

Filename: core/Model.php

Line Number: 51

and

Quote:Fatal error: Call to a member function get() on a non-object in C:\wamp\www\ci\application\models\site_model.php on line 7

I have done everything like the tutorial said

here is my controller
Code:
<?php

class Site extends CI_Controller{

  function index(){
   $this->load->model('site_model');
   $data['records'] = $this->site_model->getAll();
   $this->load->view('home', $data);
  }


}

?>

This is my model
Code:
<?php
class Site_model extends CI_Model
{

  function getAll()
  {
   $q = $this->db->get('test');
   if($q->num_rows > 0)
   {
    foreach($q->result() as $row)
    {
     $data[] = $row;
    }
  
    return $data;
   }
  }
}
?>

This is my view
Code:
<html>
  <head>
   <title>
   </title>
  </head>

  <body>
   <div id="container">
    <p>My view has been loaded</p>
   <pre>
    &lt;?php print_r($records); ?&gt;
   </pre>
   </div>
  
  &lt;/body&gt;
&lt;/html&gt;




undefined property - El Forum - 08-10-2012

[eluser]john_j[/eluser]
Code:
$q = $this->db->get('test');

Did you load 'test'?


undefined property - El Forum - 08-10-2012

[eluser]cerberus478[/eluser]
I'm sorry but what do you mean?


undefined property - El Forum - 08-10-2012

[eluser]cerberus478[/eluser]
Hi

Thanks for your help I just realized that my database name was spelled differently then when I add it to the coding


undefined property - El Forum - 08-10-2012

[eluser]Massaki[/eluser]
[quote author="john_j" date="1344609985"]
Code:
$q = $this->db->get('test');

Did you load 'test'?[/quote]

Code:
$q = $this-db->get('test');
does the same as:
Code:
$q = mysql_query("SELECT * FROM 'test'");