![]() |
Model loaded twice with child property empty on the first load. Why? - Printable Version +- CodeIgniter Forums (https://forum.codeigniter.com) +-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20) +--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23) +--- Thread: Model loaded twice with child property empty on the first load. Why? (/showthread.php?tid=47430) |
Model loaded twice with child property empty on the first load. Why? - El Forum - 12-08-2011 [eluser]Unknown[/eluser] Hi, I'm quite new to CI but old to PHP. I'm a little confused with extending a model and was wondering if someone could point me in the right direction. I have core/MY_Model.php that extends CI_Model. MY_Model.php has a protected property named $_table declared. I have models/example_model.php that extends MY_Model. example_model.php has a protected property named $_table that contains the string 'examples'. When my controller is instantiated, it loads example_model in the constructor. It seems my model is being loaded twice, the first time around, $this->_table is empty but gets populated the second time it's loaded. This isn't normal and I was wondering what I'm doing wrong here. All my code is below. controllers/examples.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); models/example_model.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); core/MY_Model.php Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); My log file: Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); ?> With the above code, I see: Code: 21 # So, only on the second round does my property become populated. But why is it being loaded twice, to begin with? Thanks! |