How to display messages of a 500 error in CodeIgniter?

3

I already tried with the directive init_set , the file index.php is set to ENVIRONMENT=DEVELOPMENT , I searched a lot on the web and nothing worked for me.

I do not have access to server configuration files, that's why I need to activate the messages, because doing debugging is complicated like that.

Solution   This was the modification I made in the index.php

define('ENVIRONMENT',   'development');
/**** ERROR REPORTING
Different environments will require different levels of error reporting.
By default development will show errors but testing and live will hide them.*/

switch (ENVIRONMENT)
{
case 'development':  
    error_reporting( E_ALL );
    ini_set('display_errors', 1 );
break;

case 'testing':
case 'production':
    ini_set('display_errors', 0);
    if (version_compare(PHP_VERSION, '5.3', '>='))
    {
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
    }
    else
    {
        error_reporting(E_ALL & ~E_NOTICE & ~E_STRICT & ~E_USER_NOTICE);
    }
break;

default:
    header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
    echo 'The application environment is not set correctly.';
    exit(1); // EXIT_ERROR
}
    
asked by Sonia Toledo 24.01.2018 в 21:03
source

1 answer

3

For old versions of CodeIgniter

The index.php file contains a call to ini_set('error_reporting', ..); , to change the behavior with that type of errors.

This is the default file:

/*
|---------------------------------------------------------------
| PHP ERROR REPORTING LEVEL
|---------------------------------------------------------------
|
| By default CI runs with error reporting set to ALL.  For security
| reasons you are encouraged to change this when your site goes live.
| For more info visit:  http://www.php.net/error_reporting
|
*/
    error_reporting(E_ALL);

Below that line, add ini_set('display_errors', 1); and errors will be displayed.

In the current version of CodeIgniter (January 2018) .

The index.php has a switch and a variable to indicate the type of environment:

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 *
 * You can load different configurations depending on your
 * current environment. Setting the environment also influences
 * things like logging and error reporting.
 *
 * This can be set to anything, but default usage is:
 *
 *     development
 *     testing
 *     production
 *
 * NOTE: If you change these, also change the error_reporting() code below
 */
    define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 *
 * Different environments will require different levels of error reporting.
 * By default development will show errors but testing and live will hide them.
 */
switch (ENVIRONMENT)
{
    case 'development':
        error_reporting(-1);
        ini_set('display_errors', 1);
    break;
    case 'testing':
    case 'production':
        ini_set('display_errors', 0);
        error_reporting(E_ALL & ~E_NOTICE & ~E_DEPRECATED & ~E_STRICT & ~E_USER_NOTICE & ~E_USER_DEPRECATED);
    break;
    default:
        header('HTTP/1.1 503 Service Unavailable.', TRUE, 503);
        echo 'The application environment is not set correctly.';
        exit(1); // EXIT_ERROR
}

You only need to change the value in this function:

define('ENVIRONMENT', isset($_SERVER['CI_ENV']) ? $_SERVER['CI_ENV'] : 'development');

It is likely that errors are not shown because the value is set to production instead of development .

    
answered by 24.01.2018 / 21:27
source