我将一个钩子配置为在最终呈现的页面发送到浏览器之后运行。
$hook['post_system'] = array(
'filepath' => 'hooks',
'filename' => 'notes_hooks.php',
'class' => 'Notes_hooks',
'function' => 'write_notes',
);我的笔记钩子类是-
class Notes_hooks extends CI_Hooks {
function __construct()
{
parent::__construct();
$this->CI = get_instance();
}
function write_notes()
{
if(isset($this->CI->notes_model))
{
$this->CI->notes_model->batch_insert();
}
}
}这一切都运行得很好,并且运行它应该执行的功能,除此之外,它在输出发送到浏览器之前执行该功能。例如,如果我在以下位置添加一个睡眠
$this->CI->notes_model->batch_insert();然后,当我加载页面时,它会休眠,然后输出,而不是在PHP在后台休眠的情况下将页面呈现和输出到浏览器。
我一定漏掉了什么?
发布于 2012-02-28 18:30:22
问题实际上是redirect()调用了我的控制器,不知何故导致钩子出了问题。我通过创建自定义重定向函数解决了这个问题。
请参阅:http://codeigniter.com/forums/viewthread/134631/#664913
https://stackoverflow.com/questions/9464547
复制相似问题