![]() |
undefined property - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21) +--- Thread: undefined property (/showthread.php?tid=34722) Pages:
1
2
|
undefined property - El Forum - 10-08-2010 [eluser]OliverHR[/eluser] This is beacuse model is not loaded [quote author="f0n3man" date="1286486020"] I am having a problem getting an error message from the controller that the property Site::$site_model is undefined. [/quote] If you dont load model object instance is not created. [quote author="f0n3man" date="1286486020"] the php error in the system log states: 'Call to a member function get_records() on a non-object in /path/etc...'. [/quote] I can't see where are you loading your model [quote author="f0n3man" date="1286486020"] and even have the model loaded in the controller [/quote] put this on your constructor: Code: $this->load->model('site_model'); undefined property - El Forum - 10-08-2010 [eluser]f0n3man[/eluser] Here's the code just run with the same error: Code: Controller: Screen Error: A PHP Error was encountered Severity: Notice Message: Undefined property: Welcome::$site_model Filename: controllers/welcome.php Line Number: 17 error.log entry: PHP Fatal error: Call to a member function get_records() on a non-object in /path-to-files/application/modules/welcome/controllers/welcome.php on line 17 undefined property - El Forum - 10-08-2010 [eluser]kirtan.n[/eluser] This worked for me on CI 1.7.2 Controller: class Welcome extends Controller { function Welcome() { parent::Controller(); $this->load->database(); $this->load->helper('url'); $this->load->helper('form'); $this->load->model('site_model'); $this->output->enable_profiler(TRUE); } function index() { $data['records'] = $this->site_model->get_records(); $this->load->view('site_view', $data); } } Model: class Site_model extends Model { function Site_model() { parent::Model(); } function get_records() { $q = $this->db->get('data'); if($q->num_rows() > 0) { foreach ($q->result() as $row) { $data[] = $row; } return $data; } } } undefined property - El Forum - 10-08-2010 [eluser]f0n3man[/eluser] That tells me there must be a configuration problem. The call to CI_Model has to be there with CI 2 or it throws an error. I guess the only thing to do is start over. Someone else did the install and configuration. I will do it myself this time. undefined property - El Forum - 10-09-2010 [eluser]InsiteFX[/eluser] You did not mention that you were using modules or who's module code your using? Your problem has to do with your modules! InsiteFX undefined property - El Forum - 10-09-2010 [eluser]f0n3man[/eluser] You are correct, I am using modules, and that may be the problem. Like I said, I did not set this up, and so I will be researching this and setting up my own site. I have done some reading and see changes that need to be made to the code. Thanks for all your help, and I'll let you know how it goes. |