user1250526 user1250526 - 2 months ago 7
PHP Question

Message: Undefined property: Site::$Site_model - CodeIgniter

I am auto loading the library site_model already in autoload config, and this is the error I am getting:

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Site::$Site_model

Filename: controllers/site.php

Line Number: 16

Fatal error: Call to a member function add_record() on a non-object in /Applications/XAMPP/xamppfiles/htdocs/BLOCK/application/controllers/site.php on line 16


class Site extends CI_Controller {

function index(){


function create(){

$data = array(
'subject' => $this->input->post('subject'),
'body' => $this->input->post('body')







class Site_model extends CI_Model {

function get_records()

$query = $this->db->get('items');
return $query->result();

function add_record()
$this->db->insert('items', $data);

function update_record()
$this->db->where('id', 1);
$this->db->update('items', $data);


function delete_record()
$this->db->where('id', $this->url->segment(3));




and the view:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="" xml:lang="en" lang="en">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>

<style type="text/css" media="screen">
label {display:block;}

<?php echo form_open('site/create'); ?>

</label for="subject">Subject</label>
<input type="text" name="subject" id="subject">

</label for="body">Body</label>
<input type="text" name="body" id="body">
<input type="submit" value="Submit">
<?php echo form_close();?>

What do you guys reckon?

Much appreciated

$this->load->model('Site_model'); # <- add this