我有一些代码,在请求发送到客户端并关闭后,我想工作,因此我想post_system
从控制器内部向系统添加一个钩子,因此该post_system
钩子仅在调用特定方法时才运行。
CodeIgniter
在某些变通办法中允许这样做?
我的版本是 3.0rc3
应该有可能。一种方法是按照文档所述设置post_system挂钩- $config['enable_hooks'] = TRUE;
,在中定义挂钩application/config/hooks.php
,然后编写挂钩类。
在将使用post_system挂钩的控制器中,定义一个变量,该变量将用于确定挂钩函数是否应实际运行。在构造函数中将默认值设置为FALSE,并在您想到的特定方法中将其设置为TRUE。
在post_system_hook函数中检查此var的值。您可能首先要检查控制器是否应该被挂接。假设班级为“欢迎”;
post_system_hook_function(){
//the type of $CI will be the name of the controller
if(get_class($CI) !== 'welcome') {
return false;
}
if(! $var_that_flags_do_the_task){
return false
}
//do post system code here
}
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句