我可以扩展CI_Profiler类以显示SESSION变量吗?

时间:2010-04-21 23:29:17

标签: php codeigniter session

如果是这样......任何想法如何?

2 个答案:

答案 0 :(得分:5)

您可能对这篇关于adding sessions to the profiler的帖子感兴趣。基本上它可以通过创建MY_Profiler.php文件并复制并粘贴此代码来实现:

    <?php if(!defined('BASEPATH')) exit('No direct script access allowed');
    class MY_Profiler extends CI_Profiler {
    /**
     * Adds session data to the profiler
     * Adds a table row for each item of session data with the key and value
     * Shows both CI session data and custom session data
     */
    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;'>&#36;_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;    
    }

    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();
        $output .= $this->_compile_session();

        $output .= '</div>';

        return $output;
    }
} 

答案 1 :(得分:0)

当然可以,只需创建一个MY_profiler并添加两个方法:run()和_compile_session() run()与父母一样只需复制代码&amp;最后添加_compile_session,_compile_session可以与_compile_post具有相同的代码,只需将$ _POST更改为$ _SESSION