pcjingl 发表于 2014-8-9 10:50:32

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

本帖最后由 pcjingl 于 2014-8-9 11:02 编辑

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

首先打开"system\libraries\Profiler.php",在"$_available_sections"数组中增加一个"load_files",类似这样:
    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()方法进行修改):
    /**
   * 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",编辑并增加一行代码:
$lang['profiler_load_files']    = 'LOAD FILES';

OK! 在你的控制器中激活该分析器($this->output->enable_profiler(TRUE);),前台刷新,效果怎么样?

pcjingl 发表于 2014-8-9 10:55:15

附一个原版CI的运行调试的效果

0index.php
1system\core\CodeIgniter.php
2system\core\Common.php
3application\config\constants.php
4system\core\Benchmark.php
5application\config\config.php
6system\core\Hooks.php
7system\core\Config.php
8system\core\Utf8.php
9system\core\URI.php
10system\core\Router.php
11application\config\routes.php
12system\core\Output.php
13application\config\mimes.php
14system\core\Security.php
15system\core\Input.php
16system\core\Lang.php
17system\core\Controller.php
18application\controllers\welcome.php
19system\core\Loader.php
20application\config\autoload.php
21application\views\welcome_message.php
22system\libraries\Profiler.php
23application\config\profiler.php
24system\language\english\profiler_lang.php


页: [1]
查看完整版本: 让CI 分析器(Profiler) 能够显示包含的文件