Welcome Guest, Not a member yet? Register   Sign In
How to extending/modify the Profiler?
#1

[eluser]altrano[/eluser]
Hello,

I just play some games with CI and take a look at the profiler, but i miss some infos on it like
Code:
Session Data
Messages that i have set to debug (log_message('debug', 'some message'))

and somethings. Is there a way to do that easely? without hacking core classes?

i searched on user_guide but i can't find somethings like that, but i'm sure its possible, or not?

thanks for tips snippets or what ever Smile
#2

[eluser]kaejiavo[/eluser]
Hi,

to extend the Profiler you have to create a file MY_Profiler.php in applications/libraries
In this file you can define overwrites for the original profiler functions.

This code example works for CI2.0, in CI1.7.2 the usage is a bit different.
Code:
/**
* extend ci2 profiler
*
*/
class MY_Profiler extends CI_Profiler {

    function MY_Profiler($config = array())
    {
// add your needed sections to the _available_sections array here
        $this->_available_sections[] = 'mysection';
        $this->_available_sections[] = 'session';
        parent::CI_Profiler($config);
    }

// for each new section define the output like in this example for sessions
// function name: _compile_mysection

    /**
     * Adds ... to profiler
     */
    function _compile_mysection() {}

    /**
     * Adds session data to the profiler
     * @return string
     */
    function _compile_session()
    {
        $output = "\n\n";
        $output .= '<fieldset style="border:1px solid #009999;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#009999;">&nbsp;&nbsp;' . 'SESSION DATA' . '&nbsp;&nbsp;</legend>';
        $output .= "\n";

        if (!is_object($this->CI->session))
        {
            $output .= "<div style='color:#009999;font-weight:normal;padding:4px 0 4px 0'>" . 'No SESSION data exists' . "</div>";
        }
        else
        {
            $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
            $sess = get_object_vars($this->CI->session);

            foreach ($sess['userdata'] as $key => $val)
            {
                if (!is_numeric($key))
                {
                    $key = "'" . $key . "'";
                }

                $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_SESSION[" . $key . "]&nbsp;&nbsp; </td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;'>";

                if (is_array($val))
                {
                    $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
                }
                else
                {
                    $output .= htmlspecialchars(stripslashes($val));
                }

                $output .= "</td></tr>\n";
            }

            $output .= "</table>\n";
        }

        $output .= "</fieldset>";

        return $output;
    }
}

/* End of file MY_Profiler.php */
/* Location: ./application/libraries/MY_Profiler.php */

Marco
#3

[eluser]altrano[/eluser]
[quote author="mawi27" date="1287925029"]Hi,

to extend the Profiler you have to create a file MY_Profiler.php in applications/libraries
In this file you can define overwrites for the original profiler functions.

This code example works for CI2.0, in CI1.7.2 the usage is a bit different.
Code:
/**
* extend ci2 profiler
*
*/
class MY_Profiler extends CI_Profiler {

    function MY_Profiler($config = array())
    {
// add your needed sections to the _available_sections array here
        $this->_available_sections[] = 'mysection';
        $this->_available_sections[] = 'session';
        parent::CI_Profiler($config);
    }

// for each new section define the output like in this example for sessions
// function name: _compile_mysection

    /**
     * Adds ... to profiler
     */
    function _compile_mysection() {}

    /**
     * Adds session data to the profiler
     * @return string
     */
    function _compile_session()
    {
        $output = "\n\n";
        $output .= '<fieldset style="border:1px solid #009999;padding:6px 10px 10px 10px;margin:20px 0 20px 0;background-color:#eee">';
        $output .= "\n";
        $output .= '<legend style="color:#009999;">&nbsp;&nbsp;' . 'SESSION DATA' . '&nbsp;&nbsp;</legend>';
        $output .= "\n";

        if (!is_object($this->CI->session))
        {
            $output .= "<div style='color:#009999;font-weight:normal;padding:4px 0 4px 0'>" . 'No SESSION data exists' . "</div>";
        }
        else
        {
            $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
            $sess = get_object_vars($this->CI->session);

            foreach ($sess['userdata'] as $key => $val)
            {
                if (!is_numeric($key))
                {
                    $key = "'" . $key . "'";
                }

                $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;'>$_SESSION[" . $key . "]&nbsp;&nbsp; </td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;'>";

                if (is_array($val))
                {
                    $output .= "<pre>" . htmlspecialchars(stripslashes(print_r($val, true))) . "</pre>";
                }
                else
                {
                    $output .= htmlspecialchars(stripslashes($val));
                }

                $output .= "</td></tr>\n";
            }

            $output .= "</table>\n";
        }

        $output .= "</fieldset>";

        return $output;
    }
}

/* End of file MY_Profiler.php */
/* Location: ./application/libraries/MY_Profiler.php */

Marco[/quote]

Thanks what is the different between 2.0 1.7.2 for this modifications?
Not anyone have this do with 1.7.2 ??
#4

[eluser]kaejiavo[/eluser]
[quote author="altrano" date="1287952819"]

Thanks what is the different between 2.0 1.7.2 for this modifications?
Not anyone have this do with 1.7.2 ??[/quote]

In 1.7.2 you have to overwrite the run() function like this:
Code:
class MY_Profiler extends CI_Profiler {

    /**
     * Adds mysection data to the profiler
     */
    public function _compile_mysection() {

    $output = ...
    return $output;
    }

    /**
     * Adds session data to the profiler
     */
    function _compile_session() {
    // same code as in example above
    $output = ...
    return $output;
    }

    // overwrite run()
    function run() {
    $output = "<div id='codeigniter_profiler' style='clear:both;background-color:#fff;padding:10px;'>";

    $output .= $this->_compile_uri_string();
    $output .= $this->_compile_controller_info();
    $output .= $this->_compile_memory_usage();
    $output .= $this->_compile_benchmarks();
    $output .= $this->_compile_get();
    $output .= $this->_compile_post();
    $output .= $this->_compile_queries();
    // add your sections here
    $output .= $this->_compile_mysection();
    $output .= $this->_compile_session();

    $output .= '</div>';

    return $output;
    }

Marco
#5

[eluser]altrano[/eluser]
Ok now i have sessions, cookies, uri_vars, template_vars.

But now the only one last debug vars with debug vars i mean all the data where set in log_message() like
Code:
log_message('debug', 'Controller X Loaded');

how the hell can fetch this and pass to the profiler?? I can't find any solutions for that.

thanks for helping. Smile
#6

[eluser]WanWizard[/eluser]
extend the Log library, overload the write_log() method, capture all log messages into an array, and read that array in the profiler.




Theme © iAndrew 2016 - Forum software by © MyBB