2011-04-27 58 views
1

我正在努力启用CodeIgniter中的分析器。我已经将它添加到$libraries配置数组中,所以它应该被自动加载。但我得到的错误...使用CodeIngniter Profiler

Fatal error: Call to a member function enable_profiler() on a non-object in C:\......\application\core\publiccontroller.php on line 6 

我的代码是:

<?php 
class PublicController extends CI_Controller { 
    public function __construct() { 
     // enable profiler for development 
     if (ENVIRONMENT == 'development') { 
      $this->output->enable_profiler(true); 
     } 
    } 
} 
?> 

autoload.php具有....

/* 
| ------------------------------------------------------------------- 
| Auto-load Libraries 
| ------------------------------------------------------------------- 
| These are the classes located in the system/libraries folder 
| or in your application/libraries folder. 
| 
| Prototype: 
| 
| $autoload['libraries'] = array('database', 'session', 'xmlrpc'); 
*/ 

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

我在做什么错?我正在使用CI版本2

回答

2

正如注意:此建议解决了CI 1.x中的类似问题,但未在CI 2中测试。 问题是,我怀疑是您在调用构造函数在对象完全启动之前。你能确认$ this-> load是否存在?如果你把parent::__construct();作为构造函数的第一行会发生什么?

+2

这是完全正确的,需要在调用它的方法之前构造父类CI_Controller。 @Webnet,你不需要加载分析器:它不是一个库,它是总是加载的Output类的一部分。 – 2011-04-27 04:49:56

+0

Doh!史诗般的失败,谢谢! – Webnet 2011-04-27 13:28:04

+0

@Webnet我知道这个的原因是因为我在CI模型中工作的问题多于我的* headdesks *。 – cwallenpoole 2011-04-27 14:40:05