【问题标题】:Can I extend the CI_Profiler class to display SESSION variables as well?我可以扩展 CI_Profiler 类来显示 SESSION 变量吗?
【发布时间】:2010-04-21 23:29:16
【问题描述】:

如果是这样......你知道怎么做吗?

【问题讨论】:

    标签: php codeigniter session


    【解决方案1】:

    您可能对这篇关于 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;
        }
    } 
    

    【讨论】:

      【解决方案2】:

      当然可以,只需创建一个 MY_profiler 并添加两个方法:run() 和 _compile_session() run() 与父级相同,只需复制代码并在末尾添加 _compile_session 并且 _compile_session 可以具有与 _compile_post 相同的代码,只需将 $_POST 更改为 $_SESSION

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多