PHP Codeigniter - Undefined property on controller -
i new codeigniter , version using latest codeigniter v2.1.4.
i doing simple crud start making own web blog it's getting error message on controller following.
message: undefined property: site::$site_model
controller
function blog() { $data = array(); $query = $this->site_model->get_records(); if (isset($query)) { $data['records'] = $query; } $data['main_content'] = 'blog'; $this->load->view('includes/template', $data); }
it's complaining on line $query = $this->site_model->get_records();
model
function get_records() { $query = $this->db->get('data'); return $query->result(); }
db library loaded well..
$autoload['libraries'] = array('database');
what doing wrong?
before need load model
like
$data = array(); $this->load->model('site_model'); //here $query = $this->site_model->get_records();
when ever dealing model functions makesure before need load model well.
as hashem qolami said can auto load model like
$autoload['model'] = array('model1', 'model2');
but in opinion auto loading of models may create performance issues(iam not sure) can this.
Comments
Post a Comment