For enabling profiling in an application, add the below code in any method of the controller before loading the view.
[php]$this->output->enable_profiler(TRUE);[/php]
Once the CodeIgniter Profiler is enabled, a report regarding how fast the page loaded, appears at the page bottom.
Enabling Profiler for multiple pages
Suppose to apply the concept of profiling for multiple pages or for entire application, such that the methods should not get ugly for putting the above code in every method seeking profiling. So, to overcome the problem, Hooks feature of CodeIgniter is used to enabled/disabled profiling for the whole applications depending on the configuration file value which will be TRUE/FALSE. For Example,
Step-1 : Create a file
hooks.classes.php
in the folder path
application/hooks and enter the below code.
[php]
class ProfilerHandler
{
function EnableProfiler()
{
$CI = &get_instance();
$CI->output->enable_profiler( config_item('enable_hooks') );
}
}
[/php]
Step-2 : Create a file
hooks.php
if not present in
application/config directory and enter the below code.
[php]
$hook['post_controller_constructor'][] = array(
'class' => 'ProfilerHandler',
'function' => 'EnableProfiler',
'filename' => 'hooks.classes.php',
'filepath' => 'hooks',
'params' => array()
);
[/php]
Step-3 : Then enable hooks by setting the flag of $config['enable_hooks'] to TRUE. This step is done in
config/config.php.
[php]
$config['enable_hooks'] = TRUE; // TRUE or FALSE depending upon your choice, what you want enable/disable profiling
[/php]