• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
post_controller_constructor hook not loading $this->session

#1
[eluser]Webnet[/eluser]
My problem is that I can't access $this->session within my Application controller. Is this functionality not available to the post_controller_constructor hook ?

hooks.php

Code:
$hook['post_controller_constructor'] = array(
    array(
        'class' => 'application',
        'function' => 'preController',
        'filename' => 'application.php',
        'filepath' => 'controllers'
    )
);

application.php

Code:
class Application extends Controller {
    /*
     * The application controls logic which is global to the entire application and not on any specific page.
     */
    public function __construct() {
        parent::Controller();
        
        $this->load->library('session');
        print_r($this->session);
        exit;
    }
}

#2
[eluser]bubbafoley[/eluser]
If you're using CI 2.0 it should look like this:

Code:
class Application extends CI_Controller {
    /*
     * The application controls logic which is global to the entire application and not on any specific page.
     */
    public function __construct() {
        parent::__construct();
        $this->load->library('session');
        print_r($this->session);
        exit;
    }
}

What is that hook supposed to be doing? It's looking for a function preController() in application/controllers/application.php which doesn't appear to exist.

#3
[eluser]Webnet[/eluser]
The function does exist, I didn't post the whole class because it shouldn't matter, it fails at the constructor.

#4
[eluser]bubbafoley[/eluser]
what is the error you are getting?

#5
[eluser]Webnet[/eluser]
The below class works, but my original Application controller that's loaded by the hook does not load the session.

Code:
class AbstractController extends Controller {
    protected $current_user,
              $current_company,
              $jsFiles;

    /**
     * AbstractController Construct
     *
     * @return AbstractController
     */
    public function __construct($skipRedirect = false) {
        parent::Controller();
        
        $this->load->library('session');
        $this->load->library('form_validation');
        $this->load->database();
    }

Fatal error: Call to a member function userdata() on a non-object in application.php on line 47

#6
[eluser]bubbafoley[/eluser]
your hook class should not be a controller.

try this:

hooks.php
Code:
$hook['post_controller_constructor'] = array(
    array(
        'class' => 'Application',
        'function' => 'preController',
        'filename' => 'Application.php',
        'filepath' => 'hooks'
    )
);

application/hooks/application.php
Code:
<?php

class Application {

  function preController()
  {
      $ci =& get_instance();
      print_r($ci->session);
  }

}

#7
[eluser]Webnet[/eluser]
Thanks!


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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