I'm not sure I understand what you're looking for. As far as I know, the code you included already works fine. In fact, I have a method in my base controller which does this.
PHP Code:
protected function showProfiler($frontEnd = true)
{
// $this->input->is_cli_request() is deprecated in CI 3.0, but the replacement
// common is_cli() function is not available in CI 2.2.
$isCliRequest = substr(CI_VERSION, 0, 1) == '2' ? $this->input->is_cli_request() : is_cli();
if (! $isCliRequest
&& ! $this->input->is_ajax_request()
) {
if ($frontEnd == false
|| $this->settings_lib->item('site.show_front_profiler')
) {
$this->load->library('Console');
$this->output->enable_profiler(true);
}
}
}
Then I call the method in my base controller's constructor based on the ENVIRONMENT. My admin controller passes false to the method to bypass the check against the site.show_front_profiler setting.
Obviously, some of this code isn't going to work in a base CI installation without the appropriate libraries, but the basic idea should still work.