![]() |
Codeigniter - Can only load model in autload.php - 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: Codeigniter - Can only load model in autload.php (/showthread.php?tid=61230) |
Codeigniter - Can only load model in autload.php - El Forum - 10-26-2014 [eluser]Unknown[/eluser] Hi everyone, I'm going crazy because I have been using Codeigniter for ages now and I cannot seem to load a model in my view. This is what I have done. Model code (models/changelog.php): Code: ?php This is my controller (controllers/explore.php): Code: <?php if ( ! defined('BASEPATH')) exit('No direct script access allowed'); I get a Codeigniter notice telling me Message: Undefined property: Explore::$Changelog and a PHP error, Fatal error: Call to a member function get_list() on a non-object. Here is what I did Tried to autoload the database instead of only loading it in that model Tried changing the Changelog call in the contorller to lowercase Checked the connection to the database Enabled the log file, which doesn't tells me anything new Everything works correctly. After a while I found out something incredible happened: if I add the 'changelog' model in the autoload.php, it seems it can actually load it. What is going on? Another test I did: if I write Code: public function __construct() { Codeigniter - Can only load model in autload.php - El Forum - 10-26-2014 [eluser]Unknown[/eluser] After many hours of test and messing up with everything, INCLUDING configuration files... I DID IT! It was something totally above models and controllers, it was something about the hooks I called. In fact, I have a hook called languageloader.php written like this: Code: class LanguageLoader extends CI_Controller { In my hooks file it was loaded like: Code: $hook['post_controller_constructor'] = array( Since I was using **post_controller_constructor**, referring to CI doc files it is Quote:Called immediately after your controller is instantiated, but prior to any method calls happening. I believe that doing something like my $ci =& get_instance(); I couldn't instance my damn model. I fixed it by changing the hook to Code: $hook['pre_controller'] I didn't think it could have been something about the hooks and that was the reasons why I didn't post it. Thanks to everyone who tried to help me out in the while. I hope this helped someone else who was in my same trouble! |