用户
 找回密码
 入住 CI 中国社区
搜索
查看: 2524|回复: 1
收起左侧

[Others] 让CI 分析器(Profiler) 能够显示包含的文件

[复制链接]
发表于 2014-8-9 10:50:32 | 显示全部楼层 |阅读模式
本帖最后由 pcjingl 于 2014-8-9 11:02 编辑

框架运行时都包含了哪些文件?弄清这个问题可能会很有帮助。CI本身就带有分析器,具体怎么开启请查看手册的 “调试你的应用程序”,下面让我们来给它增加一个小功能。

首先打开"system\libraries\Profiler.php",在"$_available_sections"数组中增加一个"load_files",类似这样:
PHP复制代码
    protected $_available_sections = array(
                                        'benchmarks',
                                        'get',
                                        'memory_usage',
                                        'post',
                                        'uri_string',
                                        'controller_info',
                                        'queries',
                                        'load_files',
                                        'http_headers',
                                        'session_data',
                                        'config'
                                        );
复制代码

然后在类里面增加一个"_compile_load_files"方法,代码如下(这里的代码被论坛编辑器过滤了,请对比类中的_compile_http_headers()方法进行修改):
PHP复制代码
    /**
     * Compile load files information
     * Add by pcjingl
     *
     * Lists load files
     *
     * @return    string
     */

    protected function _compile_load_files()
    {
        $files = get_included_files();
       
        $output  = "\n\n";
        $output .= '<fieldset id="ci_profiler_http_headers" style="border:1px solid #000;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#000;">  '.$this->CI->lang->line('profiler_load_files').'  '.count($files).'  (<span style="cursor: pointer;">'.$this->CI->lang->line('profiler_section_show').'</span>)</legend>';
        $output .= "\n";
        $output .= "\n\n<table style='width:100%;display:none' id='ci_profiler_httpheaders_table'>\n";
 
        foreach ($files as $key => $file)
        {
            $output .= "<tr><td style='vertical-align: top;width:50%;padding:5px;color:#900;background-color:#ddd;'>".$key."  </td><td style='width:50%;padding:5px;color:#000;background-color:#ddd;'>".str_replace(FCPATH, '', $file)."</td></tr>\n";
        }
 
        $output .= "</table>\n";
        $output .= "</fieldset>";
 
        return $output;
    }
复制代码


最后找到语言文件"system\language\english\profiler_lang.php",编辑并增加一行代码:
PHP复制代码
$lang['profiler_load_files']    = 'LOAD FILES';
复制代码


OK! 在你的控制器中激活该分析器($this->output->enable_profiler(TRUE);),前台刷新,效果怎么样?
 楼主| 发表于 2014-8-9 10:55:15 | 显示全部楼层
附一个原版CI的运行调试的效果
HTML复制代码
0  index.php
1  system\core\CodeIgniter.php
2  system\core\Common.php
3  application\config\constants.php
4  system\core\Benchmark.php
5  application\config\config.php
6  system\core\Hooks.php
7  system\core\Config.php
8  system\core\Utf8.php
9  system\core\URI.php
10  system\core\Router.php
11  application\config\routes.php
12  system\core\Output.php
13  application\config\mimes.php
14  system\core\Security.php
15  system\core\Input.php
16  system\core\Lang.php
17  system\core\Controller.php
18  application\controllers\welcome.php
19  system\core\Loader.php
20  application\config\autoload.php
21  application\views\welcome_message.php
22  system\libraries\Profiler.php
23  application\config\profiler.php
24  system\language\english\profiler_lang.php
复制代码


本版积分规则