: This article describes how to use hooks in the CI framework and its functions. For more information about PHP tutorials, see. // Hooks source code
// Hooks is the hook. it is mainly used to expand base_system under the CI framework. its main function is,
// Run some developer-defined methods to implement some specific functions
// Define the method to be started at CI startup in application/config/hooks. php
$ 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 ')
);
// The hooks source code first checks whether the hooks (custom similar to the preceding array) exists or whether it is a two-digit array.
If (isset ($ this-> hooks [$ which] [0]) AND is_array ($ this-> hooks [$ which] [0]) {
// If yes, the system executes the loop and runs run_hook.
Foreach ($ this-> hooks [$ which] as $ val ){
$ This-> _ run_hook ($ val );
}
} Else {
// If not, directly run hooks
$ This-> _ run_hook ($ this-> hooks [$ which]);
}
// Set $ this-> in_progress = TRUE below. it mainly prevents calling a hook at the same time. when a new object is added,
// 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 how to use hooks in the CI framework and its functions, including some content, and hope to help those who are interested in PHP tutorials.