my model's '_construct' function has issues with 'new' - 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: my model's '_construct' function has issues with 'new' (/showthread.php?tid=13626) |
my model's '_construct' function has issues with 'new' - El Forum - 11-30-2008 [eluser]Teks[/eluser] Please, someone tell me what I'm doing wrong. I have a simple page_model file for a 'Page_model' class, which is: Code: class Page_model extends Model { I then create a 'Page' controller, whose job is just to create a new page_model object, and pass it on to the view: Code: class Page extends Controller { The 'page_view' file, as you can expect, is very, very simple - all it has to do is show the $title variable from the page_model: Code: <html> For some reason, however, the $title instance variable is not being set by the class' _constructor method, and the title comes up empty in the view. I have already done some testing, trying to figure out what is happening. 1) I used class_exists() in the controller, after $this->load->model, to ensure that the class description was actually being included. It is - in the controller, after loading the model, "class_exists('Page_model')" returns TRUE. 2) I used the instanceof operator to ensure that the $data variable was being created as an instance of the Page_model class - it is: in the controller, "$data instanceof Page_model" returns TRUE. 3) Finally, I used isset() to check whether $data->title was being set by the _constructor function - and it isn't. In the controller, "isset($data->title)" returns FALSE. So, it seems to me, that when '$data = new Page_model' is being called, the _construct function is either not being called, or it is for some reason failing to set the $title of the object. Am I missing something really shamefully obvious? my model's '_construct' function has issues with 'new' - El Forum - 11-30-2008 [eluser]Murodese[/eluser] __construct() (double underscore) my model's '_construct' function has issues with 'new' - El Forum - 11-30-2008 [eluser]Teks[/eluser] [quote author="Murodese" date="1228066790"]__construct() (double underscore)[/quote] Duuuuh!!! Never have I been SO glad to be SO stupid! ;-P Many, many thanks! |