您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息
三六零分类信息网 > 吕梁分类信息网,免费分类信息发布

CI框架下hooks使用说明以及它的作用

2025/6/10 0:38:22发布4次查看
//hooks源码
//hooks即钩子,主要作用是ci框架下扩展base_system,他的主要作用是在ci启动时,
//运行一些开发者定义的一些方法,来实现一些特定的功能
//在application/config/hooks.php中定义的要在ci启动时启动的方法定义
$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源码 首先判断hooks中(即自定义的类似于上面数组)是否存在或者是不是二位数组
if (isset($this->hooks[$which][0]) and is_array($this->hooks[$which][0])){
//如果是则进行循环,并且运行run_hook
foreach ($this->hooks[$which] as $val){
$this->_run_hook($val);
}
}else{
//如果不是,则直接运行hooks
$this->_run_hook($this->hooks[$which]);
}
//下面设置$this->in_progress = true;主要是防止同时调用一个hook,当new了一个新的对象后,
//就要把in_progress标记为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;
以上就介绍了ci框架下hooks使用说明以及它的作用,包括了方面的内容,希望对php教程有兴趣的朋友有所帮助。
吕梁分类信息网,免费分类信息发布

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product