在Codeigniter中使用FirePHP进行调试

本文介绍的方法,力图在使用FirePHP的时候不影响Codeigniter的代码,也就是说以后Codeigniter的升级不会受FirePHP插件的影响。

具体使用步骤如下:

1. 下载相关插件

打开Firefox,确认网络面板已经开启。

2. 下载FirePHP Core Library文件

下载地址:http://www.firephp.org/DownloadRelease/FirePHPLibrary-FirePHPCore-0.3.2 (或更新版本)

解压后将文件 FirePHP.class.php 拷贝到 /application/libraries/ 目录,并修改文件名为 firephp.php。

3. 设置autoload

修改文件 /application/config/autoload.php,让firephp库自动加载:

$autoload['libraries'] = array('firephp');

4. 修改firephp.php文件

在firephp.php文件中类的声明之前(line 60左右)加入如下代码,便于使用config中的设置来打开关闭firephp。

$CI = & get_instance();
if($CI->config->item('enable_firephp'))
define('ENABLE_IN_CONFIG',true);
else
define('ENABLE_IN_CONFIG',false);

在文件中搜索protected $enabled = true,将其替换为 protected $enabled = ENABLE_IN_CONFIG

 5. 配置config文件

在application/config/目录下找到config.php,增加如下一行内容:

$config['enable_firephp'] = true;

 6. 开始使用吧

常用使用方法:

  • $this->firephp->log($myvariable) : 在FirePHP控制台打印出变量
  • $this->firephp->warn($myvariable) : 在FirePHP控制台打印出变量并归类为warning
  • $this->firephp->error($myvariable) : 在FirePHP控制台打印出变量并归类为 error

也可以使用group:

$this->firephp->group('Test Group');
$this->firephp->log('Hello World');
$this->firephp->groupEnd();

 更多使用方法参考 FirePHP project website

posted @ 2012-04-05 15:08  令狐葱★  阅读(1215)  评论(0编辑  收藏  举报