[eluser]swgj19[/eluser]
I am working on the same old video tutorials, please help me with my errors. There are two errors. Please use specific examples as I am new to PHP and frameworks. I will not give up though.
A PHP Error was encountered
Severity: Notice
Message: Undefined property: Site::$db
Filename: core/Model.php
Line Number: 50
Fatal error: Call to a member function get() on a non-object in C:\xampp\htdocs
\ci\application\models\site_model.php on line 6
Now, here is my model, view, and controller pages.
Model(site_model.php):
<?php
class Site_model extends CI_Model {
function getAll() { //can name method whatever
$q = $this->db->get('test'); //grab table name:test from database name: ci_series
if($q->num_rows() > 0) { //If # of rows return are > than 0, then do whats next.
foreach ($q->result() as $row)
{
$data[] = $row; //by setting $data as an array, we have a new instance in the data array.
}
return $data;
}
}
}
?>
View(home.php):
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<div id="container">
<p>My view has been loaded</p>
<?php foreach($records as $row) : ?>
<h1><?php echo $row->username; ?></h1>
<?php endforeach; ?>
</div>
</body>
</html>
Controller(site.php):
<?php
class Site extends CI_Controller {
function index() {
$this->load->model('site_model'); //This is where model is loaded, but nothing done with the model yet.
$data['records'] = $this->site_model->getAll();
$this->load->view('home', $data);
}
}
?>