Welcome Guest, Not a member yet? Register   Sign In
Call get_instance() in Hook Class
#1

Hi everybody,

In my application I try to call get_instance() in pre_system hook class. But then error message appeared:

Code:
A PHP Error was encountered
Severity: Error
Message: Class 'CI_Controller' not found
Filename: core/CodeIgniter.php
Line Number: 366

that line refers to get_instance() function in core/CodeIgniter.php. After I check the pre_system hook called before the core/Controller.php included.

Any ideas how to solve this?
Reply
#2

You can't "solve" it ...

get_instance() returns your controller object, and the controller doesn't exist at 'pre_system'.
Reply
#3

To see what's available at what hook points, just open /system/CodeIgniter.php and look for the name of your hook. It will be using _call_hook(name-of-hook);
Like:
$EXT->_call_hook('pre_system');

To know what's available, it would be anything loaded BEFORE that hook is called. You can see that the controller is loaded way after that hook, so it's not available at that point.

The first available hook after a controller is instantiated is "post_controller_constructor"
Reply




Theme © iAndrew 2016 - Forum software by © MyBB