CodeIgniter Forums
What is hook - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: What is hook (/showthread.php?tid=4798)



What is hook - El Forum - 12-17-2007

[eluser]Muhammad Faisal Shabbir[/eluser]
hai to all
can some one help me to understanding the hook and why we use it in CI very frequently


What is hook - El Forum - 12-17-2007

[eluser]xwero[/eluser]
A hook is a method or a function you want to execute during one of the different stages of the page build up (short explaination).
CI calls the stages hook points.

You have to use hooks wisely because they can slow down the page build.


What is hook - El Forum - 12-17-2007

[eluser]Muhammad Faisal Shabbir[/eluser]
Thanx for ur assistence xwero


What is hook - El Forum - 12-17-2007

[eluser]ELRafael[/eluser]
Man, really? I believed that hook is from Neverland. Ok, sorry!

An example for hook is to test if user is logged in the system. You have a function that you wana run before the method.So you use inside hoook.


What is hook - El Forum - 12-17-2007

[eluser]Nick Husher[/eluser]
Hooks are a way of introducing Aspect-oriented Programming into your system, as well. Like ElRafael noted, you can use it to check a user's logged-in status, you could also use it for logging, or checking database sanity (probably a bad idea, but possible). Anything that you want executed every time a page loads, or any program responsibility you want to apply broadly across your system, you might want to put in a hook.


What is hook - El Forum - 12-27-2007

[eluser]JOKERz[/eluser]
did you use hook to check user logged-in status in your code??


What is hook - El Forum - 12-27-2007

[eluser]Nick Husher[/eluser]
I haven't personally, but I could if I wanted to. It probably introduces a level of complexity that you don't need in small projects (lightweight CMSes, etc) but in a larger environment where your login might be somewhat more complicated or it exists on every page, moving that code into a hook might be helpful.


What is hook - El Forum - 12-27-2007

[eluser]JOKERz[/eluser]
hmm.... i see....
thanks for your advise.


What is hook - El Forum - 12-27-2007

[eluser]Majd Taby[/eluser]
check out http://ellislab.com/forums/viewthread/67126/ for a live example of how to use hooks to secure a whole application.