Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/codeigniter/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
确定捕捉php/codeigniter错误的位置_Php_Codeigniter_Error Handling - Fatal编程技术网

确定捕捉php/codeigniter错误的位置

确定捕捉php/codeigniter错误的位置,php,codeigniter,error-handling,Php,Codeigniter,Error Handling,我正在尝试捕获web应用程序中所有意外的错误消息,并向最终用户显示一条通用消息。但是现在,我的页面上出现了几个php/codeigniter错误消息 我的控制器中有以下逻辑: public function logs() { try { $data['logcontents'] = $this->switches_model->get_logs($this->uri->segment(7), $this->uri->segment(4)

我正在尝试捕获web应用程序中所有意外的错误消息,并向最终用户显示一条通用消息。但是现在,我的页面上出现了几个php/codeigniter错误消息

我的控制器中有以下逻辑:

public function logs()
{
    try {
        $data['logcontents'] = $this->switches_model->get_logs($this->uri->segment(7), $this->uri->segment(4));
        $data['main_content']='logs';
        $this->load->view('includes/template', $data);
    }
    catch (Exception $e) {
        show_error($e->getMessage());
    }   
}// end logs
我的模型是这样的:

public function get_logs($dnsName, $switchname)
{
     try {              
            if ( $switch_obj->connect() )  {
            //do something                  
            return $data;
             }
        else {
            throw new Exception('Connection');

        }//end if
        }// end try
    catch (Exception $e) {
        print 'switches_model get_logs e handler<BR>';
        $this->error_handler($e->getMessage());
        return false;
    }
我已经在本地测试了此逻辑,当我模拟连接失败时,我收到一条错误消息,显示消息“无法连接到设备。请与管理员联系!(1)”,这正是我所期望的

但我在不同的web服务器上尝试相同的逻辑,现在,我得到了一堆额外的错误消息:

遇到一个PHP错误

严重性:通知

消息:未定义的属性:开关::$\u密码

文件名:core/Model.php

行号:51遇到PHP错误

严重性:通知

消息:未定义的属性:开关::$\u用户ID

文件名:core/Model.php

线号:51开关\u型号获取\u日志e 处理程序遇到PHP错误

严重性:警告

消息:无法修改标题信息-标题已由发送 (输出开始于 /myapp/system/core/Exceptions.php:185)

文件名:core/Common.php

行号:438遇到错误

无法连接到设备。请联系管理员!(一)

我还想知道CI的这些消息是什么意思。。。但我可以用谷歌搜索。现在,我只是想知道如何防止这些消息出现在用户面前。我只想把它们记录下来。 在CI的config.php中,我有$config['log_threshold']=1

谢谢

编辑1


我明白了为什么会出现这些错误——这是因为我没有正确地声明两个变量。但是如果你能帮我整理一下,以防止意外错误出现在GUI上,那将非常感谢

看起来像是来自CodeIgniter,但实际上是来自PHP。一般来说,您可能应该阅读PHP错误处理方面的内容,但应该是来自喜欢CI的人。通常,您应该在dev上尽可能严格地进行错误报告,在prod上它应该记录到一个文件中(如果可能的话,永远不要向最终用户显示)。

hi。我会读那篇文章。谢谢话虽如此,我已经读了一些关于电子处理的书,并试图通过在这里发布一般性问题来确保我的理解是正确的。我想知道是否有人能指出在我的代码示例中,我哪里出错了
    private function error_handler($emess)
    {
        switch ($emess)
        {
            case 'Connection':
                $userfriendlyemess = "Unable to connect to device. Please contact administrator! (1)";
                break;

            case 'Empty Data Set':
                $userfriendlyemess = "Device connected.  Unable to get data.  Please contact administrator! (3)";
                break;
            case 'Failure':
                $userfriendlyemess = "Oops!  Unable to complete command. Please contact administrator! (4)";
                break;
            //handling unknown errors   
            default:
                $userfriendlyemess = "Oops!  Something big just happened. (99)";
                log_message('error', $emess); //write to ci logs
                break;
        }
        throw new Exception($userfriendlyemess);            
    }