修改Codeigniter探查器以将输出发送到db而不是在页面上显示

sto*_*ain 5 profiler codeigniter

我想使用CI分析器作为审核应用程序的工具.但是,显然在这种情况下,我不希望输出显示在页面上,而是记录到数据库.

我以为我可以挂钩到探查器抓取相关的细节(查询,uri_string等)并将其发送到数据库中的表.

我可以扩展探查器类以将数据发送到数据库,但这并不会消除屏幕输出.我希望能够不时地正常使用分析器,因此不希望重写输出类.

任何想法都赞赏.


我最终做的是创建一个库和copylasagna Profiler.php进行修改,根据需要进行修改.

lan*_*ons 7

试试这个.将MY_Profiler.php添加到您的库/目录中(我假设您在2.0+分支;如果没有,请知道):

<?php
class MY_Profiler extends CI_Profiler {
    public function run()
    {
        $output = parent::run();
        // log output here, and optionally return it if you do want it to display
    }
}
Run Code Online (Sandbox Code Playgroud)

编辑:并自动为每个控制器启用探查器(添加到core/MY_Controller.php):

<?php
class MY_Controller extends CI_Controller {
    public function __construct()
    {
        parent::__construct();
        $this->output->enable_profiler(TRUE);
    }
}
// but each controller will have to extend MY_Controller, not CI_Controller...
class Somecontroller extends MY_Controller { //... }
Run Code Online (Sandbox Code Playgroud)