Welcome Guest, Not a member yet? Register   Sign In
Profiler extension: session & custom data
#1

[eluser]Clifford James[/eluser]
With this little extension you can view the session data in de profiler + you can dump your own data to the profiler. Arrays and objects are expandable through javascript. Beware, its kinda quick and dirty Wink

example :
Code:
$this->output->dump($contacts, '$contacts');

MY_Output.php
Code:
<?php

class MY_Output extends CI_Output {

    function dump($content, $name = NULL) {
        $debug = debug_backtrace();
        $file  = $debug[0]['file'];
        $line  = $debug[0]['line'];
        
        $this->dump[] = compact(array('content', 'name', 'file', 'line'));
    }

}

MY_Profiler.php
Code:
<?php

class MY_Profiler extends CI_Profiler {

    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".'<legend style="color:#009999;">  '.'SESSION DATA'.'  </legend>'."\n";
    
           if (!isset($this->CI->session) OR !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 ]}   </td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;'><pre>{$this->_compile_var($_SESSION[ $key ])}</pre>";
    
                 $output .= "</td></tr>\n";
            }
  
            $output .= "</table>\n";
           }
  
           $output .= "</fieldset>";

           return $output;    
      }
      
      function _compile_var($var, $tabs = 0) {
          $tabs++;
          $output  = '';
          $dump_id = 'dump_'.mt_rand();
          
          if (is_array($var)) {
              $output .= '<a href="[removed]toggle_dump(\''.$dump_id.'\')">Array('.count($var).')</a><br/>';
              $output .= '<div id="'.$dump_id.'" style="display:none;">'.str_repeat("    ", ($tabs - 1)).'{'."\n";
              foreach ($var as $key => $value) {
                  $output.= str_repeat("    ", $tabs)."[{$key}] => ".$this->_compile_var($value, $tabs)."\n";
              }
              $output .= str_repeat("    ", ($tabs - 1)).'}'.'</div>';
          } elseif (is_object($var)) {
              $output .= '<a href="[removed]toggle_dump(\''.$dump_id.'\')">Object('.count(get_object_vars($var)).')</a><br/>';
              $output .= '<div id="'.$dump_id.'" style="display:none;">'.tr_repeat("    ", ($tabs - 1)).'{'."\n";
              foreach ($var as $key => $value) {
                  $output.= str_repeat("    ", $tabs)."[{$key}] => {$this->_compile_var($value, $tabs)}\n";
              }
              $output .= str_repeat("    ", ($tabs - 1)).'}'.'</div>';
          } else {
              ob_start();
              var_dump($var);
              $output .= ob_get_clean();
          }
          
          return $output;
      }
      
      function _compile_dump() {
          $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".'<legend style="color:#009999;">  '.'DUMP DATA'.'  </legend>'."\n";
           $output .= '[removed]function toggle_dump(id) { var e = document.getElementById(id); if (e.style.display == \'block\') { e.style.display = \'none\'; } else { e.style.display = \'block\'; } }[removed]'."\n";
          
           if (!isset($this->CI->output->dump) OR !is_array($this->CI->output->dump)) {
            $output .= "<div style='color:#009999;font-weight:normal;padding:4px 0 4px 0'>".'No DUMP data exists'."</div>";
           } else {
            $output .= "\n\n<table cellpadding='4' cellspacing='1' border='0' width='100%'>\n";
    
            foreach ($this->CI->output->dump as $dump) {
                 $output .= "<tr><td width='50%' style='color:#000;background-color:#ddd;' valign='top'>";
                 if (isset($dump['name']) AND !empty($dump['name'])) $output .= "variable: {$dump['name']}<br/>";
                 $output .= "file: {$dump['file']}<br/>";
                 $output .= "line: {$dump['line']}";
                 $output .= "</td><td width='50%' style='color:#009999;font-weight:normal;background-color:#ddd;' valign='top'><pre>{$this->_compile_var($dump['content'])}</pre>";
    
                 $output .= "</td></tr>\n";
            }
  
            $output .= "</table>\n";
           }
          
           $output .= "</fieldset>";
          
           return $output;
      }
  
      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_dump();
           $output .= $this->_compile_session();
           $output .= $this->_compile_queries();

           $output .= '</div>';

           return $output;
      }
}
#2

[eluser]mikedfunk[/eluser]
Wow this is really great! It threw errors for the session part but I just combined the dump part with the session part from here: http://ellislab.com/forums/viewthread/133671/#659735 . The forum also removes the javascript stuff but I guessed on how to replace those and it works great! I love having the expandable arrays. This will be very useful in debugging without having to use firebug in firefox.




Theme © iAndrew 2016 - Forum software by © MyBB