• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot Load Session/Model in Hook

I am trying to use session information in a hook. Here is the hook

class Template extends Controller {
      function Template() {

However similar code works fine in the default controller

class DefaultController extends Controller{

    function DefaultController (){

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.

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!

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.