本文介绍了修改Codeigniter剖析器以将输出发送到db而不是显示在页面上的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I'd like to use CI profiler as a tool to audit an app. However, obviously in this case, I do not want the output to be displayed on the page, but rather be logged to the db.

我以为我可以钩入profiler抓取相关的细节(查询,uri_string等),并发送到db中的表。

I was thinking I could hook into profiler grab the relevant details (query, uri_string, etc.) and send that to a table in the db.

我可以扩展profiler类来将数据发送到db,但这不会消除屏幕输出。我想能够正常使用分析器以及不时,所以重写输出类是不可取的。

I could extend the profiler class to send data to the db, but this doesn't eliminate the output to the screen. I'd like to be able to use the profiler normally as well from time to time, so re-writing the output class isn't desirable.

任何想法赞赏。

推荐答案

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

Try this. Add MY_Profiler.php to your libraries/ directory (I assume you're in the 2.0+ branch; if not, lemme know):

<?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
    }
}

EDIT:并为每个控制器自动启用分析器(添加到core / MY_Controller.php):

And to automatically enable the profiler for each controller (add to 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 { //... }

这篇关于修改Codeigniter剖析器以将输出发送到db而不是显示在页面上的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-29 09:47