1

I am trying to load view for pre controller hook, but it is giving following error :

Call to a member function view() on null

I want to display message on screen for database connectivity from pre controller hook.

Hook controller function code is as follows:

public function check_db_connection() {
   $CI = & get_instance();
   $CI->load->view('common/footer');  }
H.joshi
  • 51
  • 8

1 Answers1

0

The problem is that at the point where the pre-controller hook is called there isn't an instance of a controller that get_instance() can return, so it returns NULL. The executing code then effectively becomes

NULL->load->view('common/footer');

Which of course is nonsense.

"pre-controller" means no controller exists yet and get_instance() returns the location of an existing controller.

You might try hooking to the 'post_controller_constructor' instead.

DFriend
  • 8,869
  • 1
  • 13
  • 26