Welcome Guest, Not a member yet? Register   Sign In
Exceptions.php - Intercepting echo
#1

[eluser]rvent[/eluser]
Hello,

I am having a little problem. I am using CodeIgniter with ExtJS and creating a login form. So far eveything works fine except when i get to the part in my library that does the "ldap_bind" and it is that the system/libraries/Exception.php says to Echo the $buffer last line in the code.
Code:
function show_php_error($severity, $message, $filepath, $line)
    {    
        $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];
    
        $filepath = str_replace("\\", "/", $filepath);
        
        // For safety reasons we do not show the full file path
        if (FALSE !== strpos($filepath, '/'))
        {
            $x = explode('/', $filepath);
            $filepath = $x[count($x)-2].'/'.end($x);
        }
        
        if (ob_get_level() > $this->ob_level + 1)
        {
            ob_end_flush();    
        }
        ob_start();
        include(APPPATH.'errors/error_php'.EXT);
        $buffer = ob_get_contents();
        ob_end_clean();
        echo $buffer;
    }

So what i've been doing is returning Json strings with success=true and success=false so that my ExtJS code can display it on a popup window. Certaintly it works fine on other failures, but the echo kind of messes things up for me at the moment...

Any idea on how to get rid of it..?

Thanks.
#2

[eluser]jtkendall[/eluser]
Hi rvent,

You can remove the echo by extending the Exceptions class. In your Application/Libraries folder create a MY_Exceptions.php file (provided you have your "subclass_prefix" still set to the default "MY_"), set the file up (see code below), modify the function to suit your needs, and that should work for you.

Code:
<?php

    class MY_Exceptions extends CI_Exceptions
    {

        function MY_Exceptions()
        {
            parent::CI_Exceptions();
        }

        function show_php_error($severity, $message, $filepath, $line)
            {    
                $severity = ( ! isset($this->levels[$severity])) ? $severity : $this->levels[$severity];

                $filepath = str_replace("\\", "/", $filepath);

                // For safety reasons we do not show the full file path
                if (FALSE !== strpos($filepath, '/'))
                {
                    $x = explode('/', $filepath);
                    $filepath = $x[count($x)-2].'/'.end($x);
                }

                if (ob_get_level() > $this->ob_level + 1)
                {
                    ob_end_flush();    
                }
                ob_start();
                include(APPPATH.'errors/error_php'.EXT);
                $buffer = ob_get_contents();
                ob_end_clean();
                echo $buffer;
            }

    }




Theme © iAndrew 2016 - Forum software by © MyBB