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

Popular posts from this blog

javascript - Laravel datatable invalid JSON response -

java - Exception in thread "main" org.springframework.context.ApplicationContextException: Unable to start embedded container; -

sql server 2008 - My Sql Code Get An Error Of Msg 245, Level 16, State 1, Line 1 Conversion failed when converting the varchar value '8:45 AM' to data type int -