dtt27783 2012-02-27 11:50
浏览 61
已采纳

Codeigniter post_system挂钩不起作用

I have a hook configured to run after the final rendered page has been sent to the browser.

$hook['post_system'] = array(
                                    'filepath' => 'hooks',
                                    'filename' => 'notes_hooks.php',
                                    'class'    => 'Notes_hooks',
                                    'function' => 'write_notes',
                );

With my notes hooks class being -

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 all runs fine and runs the function it is supposed to do, apart from that it does the function before output has been sent to the browser. For example if I add a sleep after

$this->CI->notes_model->batch_insert();

Then when I load the page it sleeps then outputs, rather than the expected rendering and output of the page to the browser with PHP sleeping in the background.

I must be missing something?

  • 写回答

1条回答 默认 最新

  • doumu1873 2012-02-28 10:30
    关注

    The issue was in fact redirect() called in my controller somehow causing the hooks to bug out. I solved the issue by creating a custom redirect function.

    See: http://codeigniter.com/forums/viewthread/134631/#664913

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?