Welcome Guest, Not a member yet? Register   Sign In
How to extending/modify the Profiler?
#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


Messages In This Thread
How to extending/modify the Profiler? - by El Forum - 10-23-2010, 09:13 PM
How to extending/modify the Profiler? - by El Forum - 10-24-2010, 01:57 AM
How to extending/modify the Profiler? - by El Forum - 10-24-2010, 09:40 AM
How to extending/modify the Profiler? - by El Forum - 10-24-2010, 10:52 AM
How to extending/modify the Profiler? - by El Forum - 10-24-2010, 01:05 PM
How to extending/modify the Profiler? - by El Forum - 10-24-2010, 01:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB