![]() |
Cannot Load Session/Model in Hook - 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: Cannot Load Session/Model in Hook (/showthread.php?tid=26218) |
Cannot Load Session/Model in Hook - El Forum - 01-08-2010 [eluser]jitterbug[/eluser] I am trying to use session information in a hook. Here is the hook Code: class Template extends Controller { However similar code works fine in the default controller Code: class DefaultController extends Controller{ This is the error I am getting A PHP Error was encountered Severity: Notice Message: Undefined property: Template::$session Filename: hooks/template.php Line Number: 17 So loading the session in a model when it was already autoloaded was a bad idea... However, it is still not recognizing session within the Template hook class. Cannot Load Session/Model in Hook - El Forum - 01-08-2010 [eluser]jitterbug[/eluser] Another case of know what youre using before you use it! $this->load->session is the correct way to grab the session. Reloading the library will cause conflicts in your code... As an aside it took me 3 hours to figure this out (and only because I used print_r($this) to sort through the tree until session. It would be nice if the autoload page told new users how to load in classes that have been autoloaded. Perhaps its there somewhere, but I really poured over the wiki, user guide, and forums to find an answer to this. Moreover it appears many users are incorrectly using $this->load->library['session'] to load the session into their controller object when in reality they just want $this->load->session. While this is obvious in retrospect I dont think it is obvious to new users who do not understand things. Thanks and yay! |