php Codeigniter 显示空白页而不是错误消息

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/9587413/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 07:12:02  来源:igfitidea点击:

Codeigniter displays a blank page instead of error messages

phpcodeigniter

提问by FlyingCat

I'm using Codeigniter, and instead of error messages I'm just getting a blank page. Is there any way to show PHP error messages instead? It's very hard to debug when I get no feedback.

我正在使用 Codeigniter,但我得到的不是错误消息,而是一个空白页。有什么办法可以显示 PHP 错误消息吗?当我没有得到反馈时,调试非常困难。

My environment is Ubuntu with Apache.

我的环境是 Ubuntu 和 Apache。

回答by Wesley Murch

Since none of the solutions seem to be working for you so far, try this one:

由于到目前为止似乎没有任何解决方案适合您,请尝试以下解决方案:

ini_set('display_errors', 1);

http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors

http://www.php.net/manual/en/errorfunc.configuration.php#ini.display-errors

This explicitly tells PHP to displaythe errors. Some environments can have this disabled by default.

这明确告诉 PHP显示错误。默认情况下,某些环境可以禁用此功能。

This is what my environment settings look like in index.php:

这是我的环境设置的样子index.php

/*
 *---------------------------------------------------------------
 * APPLICATION ENVIRONMENT
 *---------------------------------------------------------------
 */
define('ENVIRONMENT', 'development');
/*
 *---------------------------------------------------------------
 * ERROR REPORTING
 *---------------------------------------------------------------
 */
if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            // Report all errors
            error_reporting(E_ALL);

            // Display errors in output
            ini_set('display_errors', 1);
        break;

        case 'testing':
        case 'production':
            // Report all errors except E_NOTICE
            // This is the default value set in php.ini
            error_reporting(E_ALL ^ E_NOTICE);

            // Don't display errors (they can still be logged)
            ini_set('display_errors', 0);
        break;

        default:
            exit('The application environment is not set correctly.');
    }
}

回答by alexanderlukanin13

Make sure php5-mysqlis installed.

确保php5-mysql已安装。

回答by MauricioRobayo

I had this same problem and as Shayan Husaini pointed out, I had an undetected syntax error.

我遇到了同样的问题,正如 Shayan Husaini 指出的那样,我有一个未检测到的语法错误。

I solved it using the php linter in the terminal:

我在终端中使用 php linter 解决了它:

php -l file.php

You can also use something like this to use the linter in every file in some folder:

您还可以使用类似的方法在某个文件夹中的每个文件中使用 linter:

find -type f -name "*.php" -exec php -l '{}' \;

And to filter just the ones with errors:

并只过滤那些有错误的:

find -type f -name "*.php" -exec php -l '{}' \; | grep '^[^N]'

That should show files with parsing errors and the line where the error is.

那应该显示带有解析错误的文件和错误所在的行。

回答by Code Prank

This behavior occurs when you have basic php syntax error in your code. In case when you have syntax errors the php parser does not parse the code completely and didnot display anything so all of the above suggestion would work only if you have other than syntax errors.

当您的代码中有基本的 php 语法错误时,就会发生此行为。如果您遇到语法错误,php 解析器不会完全解析代码并且不显示任何内容,因此上述所有建议仅在您有语法错误以外的情况下才有效。

回答by Christian Giupponi

you can set it in the main index.php

您可以在主 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.
 */

if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(E_ALL);
        break;

    case 'testing':
    case 'production':
        error_reporting(0);
    break;

    default:
        exit('The application environment is not set correctly.');
}
}

回答by user1414182

This happens to me whenever I do autoload stuff in autoload.php like the 'database'

每当我在 autoload.php 中自动加载诸如“数据库”之类的内容时,就会发生这种情况

To resolve this, If you're using Windows OS

要解决此问题,如果您使用的是 Windows 操作系统

  1. Open your php.ini. Search and uncomment this line - extension=php_mysql.dll

    (Please also check If the PHP directive points to where your extensions is located.
    Mine is extension_dir = "C:\php-5.4.8-Win32-VC9-x86\ext")

  2. Restart Apache and refresh your page

  1. 打开你的 php.ini。搜索并取消注释此行 -extension=php_mysql.dll

    (另请检查 PHP 指令是否指向您的扩展程序所在的位置。
    我的是extension_dir = "C:\php-5.4.8-Win32-VC9-x86\ext"

  2. 重启 Apache 并刷新页面

回答by RookieDev

I had the same problem a couple days ago. My development environment is Win8 and the website was working just fine, but when i uploaded the files to production server (Linux) was displaying a blank page.

几天前我遇到了同样的问题。我的开发环境是 Win8 并且网站运行良好,但是当我将文件上传到生产服务器 (Linux) 时显示一个空白页面。

Turns out that models and controllers's filenames should start with a uppercase letter.

原来模型和控制器的文件名应该以大写字母开头

The file must be called ‘Blog.php', with a capital ‘B'.

Class names must start with an uppercase letter.

该文件必须命名为“Blog.php”,大写字母“B”。

类名必须以大写字母开头。

In windows environment this wont matter since windows does not differentiate uppercase and lowercase, but in linux environment, the files wont be displayed.

在 windows 环境中这无关紧要,因为windows 不区分大小写,但在 linux 环境中,文件不会显示。

Hope I've helped.

希望我有所帮助。

回答by Rafik Bari

Make sure you don't have a blank index.html file in your root folder. It happens :)

确保根文件夹中没有空白的 index.html 文件。它发生了:)

回答by brenjt

Try adding this to your index.php file

尝试将其添加到您的 index.php 文件中

error_reporting(E_ALL);

回答by Vytautas Krutulis

If you're using CI 2.0 or newer, you could change ENVIRONMENTtype in your index.phpto define('ENVIRONMENT', 'testing');.
Alternatively, you could add php_flag display_errors onto your .htaccessfile.

如果您使用 CI 2.0 或更新版本,您可以将ENVIRONMENT类型更改index.phpdefine('ENVIRONMENT', 'testing');.
或者,您可以添加php_flag display_errors on到您的.htaccess文件中。