Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Already on GitHub? Sign in to your account

Hooks documentation needs usage example #581

yasar11732 opened this Issue Oct 16, 2011 · 2 comments


None yet
3 participants

Current documentation for hooks needs usage example. I (and probably most people) cannot figure out how exactly to get access to loaded libraries and helpers by reading documentation found in http://codeigniter.com/user_guide/general/hooks.html


narfbg commented Jan 8, 2014

That is because at the most hook points, libraries and helpers are not yet loaded. In fact, helpers' nature is so simple that you either have the function defined or not - no special requirements to use them at all.

@narfbg narfbg closed this Jan 8, 2014


marcossffilho commented Jan 9, 2014

@yasar11732 some observations for hooks:

  • When the pre_system hooks are triggered, only the common functions, constants and the Benchmark library are loaded.
  • When the pre_controller hooks are triggered, the core global objects (like $CFG (Config Class), $IN (Input Class)) are loaded. The controller file is loaded and the hook will not be executed if the controller or the method doesn't exists (you get the show_404() instead). The function get_instance exists, but will return NULL if you use. So until now, you can load class with the common load_class() function but you can't use any function that requires the use of the controller method (like the Loader class that assigns every loaded file to the controller object, so you can use $this->db, $this->model)
  • When the post_controller_constructor are triggered, the controller is instanciated. So you can use the get_instance() and any library that uses the controller object. If you set libraries and helpers in the autoload config, they will be loaded too and ready for use.

baypup pushed a commit to baypup/CodeIgniter that referenced this issue Aug 20, 2015

Merge pull request #581 from Patroklo/2
Change in group() method to use internal where
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment