Welcome Guest, Not a member yet? Register   Sign In
undefined property
#1

[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;

#2

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

Did you load 'test'?
#3

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

[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
#5

[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'");




Theme © iAndrew 2016 - Forum software by © MyBB