Codeigniter post_system挂钩不起作用

时间:2012-02-27 11:50:36

标签: php codeigniter hook destructor

我有一个钩子,配置为在最终渲染页面发送到浏览器后运行。

$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在后台睡觉。

我一定错过了什么?

1 个答案:

答案 0 :(得分:0)

问题实际上是redirect()在我的控制器中调用,导致钩子出错。我通过创建自定义重定向功能解决了这个问题。

请参阅: http://codeigniter.com/forums/viewthread/134631/#664913