Instructions for using hooks under the CI framework and their functions

WBOY
Release: 2016-08-08 09:32:55
Original
1469 people have browsed it

//hooks source code
//hooks are hooks, their main function is to extend base_system under the CI framework, and their main function is when CI starts,
//Run some methods defined by developers to achieve some specific functions
//Method definition defined in application/config/hooks.php to be started when CI starts
$hook['pre_controller'][] = array(
                                                                                                                                                                                                     'class'                                                                                                                                                                                                                                                                                                                      'function' => 'Myfunction',
                                                                                                                                                                                                                                         'filename' => 'Myclass.php',
                                                                                                                                                                                                                                             'filepath' => 'hooks',
                                                                                                                                                                                                                                                                                                                                                                                                               

$hook['pre_controller'][] = array(
'Class' = & gt; 'myotherclass',
'FMCTION' = & GT; 'Myotherfunction',
                                                                                                                                                                                                                                         'filename' => 'Myotherclass.php',
                                                                                                                                                                                                                                             'filepath' => 'hooks',
                                                                                                                                                                                                                                                                                                                                                                                           

//hooks source code First determine whether hooks (i.e. a custom array similar to the one above) exists or is a two-digit 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 hooks directly

$this->_run_hook($this->hooks[$which]); }
//Set $this->in_progress = TRUE; below to prevent calling a hook at the same time. When a new object is created, //Just 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 introduces the instructions for using hooks under the CI framework and its functions, including relevant aspects. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template