Hooks source
Hooks is the hook, the main role is the CI framework under the expansion of Base_system, his main role is when the CI started,
Run some developer-defined methods to implement some specific functions
The method definition that is defined in application/config/hooks.php to start at CI startup
$hook [' Pre_controller '] [] = Array (
' Class ' = ' MyClass ',
' function ' = ' Myfunction ',
' filename ' = ' myclass.php ',
' FilePath ' = ' hooks ',
' params ' = = Array (' Beer ', ' wine ', ' snacks ')
);
$hook [' Pre_controller '] [] = Array (
' Class ' = ' Myotherclass ',
' function ' = ' myotherfunction ',
' filename ' = ' myotherclass.php ',
' FilePath ' = ' hooks ',
' params ' = = Array (' Red ', ' yellow ', ' blue ')
);
Hooks source first determine whether the hooks (that is, a custom similar to the above array) exists or is not a two-bit array
if (Isset ($this->hooks[$which][0]) and Is_array ($this->hooks[$which][0]) {
If yes, loop and run Run_hook
foreach ($this->hooks[$which] as $val) {
$this->_run_hook ($val);
}
}else{
If not, run the hooks directly
$this->_run_hook ($this->hooks[$which]);
}
The following setting $this->in_progress = TRUE; Prevents the invocation of a hook at the same time, when new objects are
We're going to mark in_progress as false.
$this->in_progress = TRUE;
if ($class!== FALSE) {
if (! class_exists ($class)) {
Require ($filepath);
}
$HOOK = new $class;
$HOOK-$function ($params);
}else{
if (! function_exists ($function)) {
Require ($filepath);
}
$function ($params);
}
$this->in_progress = FALSE;
The above describes the CI framework hooks use and its role, including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.