简体   繁体   English

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

[英]Codeigniter displays a blank page instead of error messages

I'm using Codeigniter, and instead of error messages I'm just getting a blank page.我正在使用 Codeigniter,但我得到的不是错误消息,而是一个空白页面。 Is there any way to show PHP error messages instead?有什么办法可以显示 PHP 错误消息吗? It's very hard to debug when I get no feedback.当我没有得到反馈时,很难调试。

My environment is Ubuntu with Apache.我的环境是 Ubuntu 和 Apache。

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 display the errors.这明确告诉 PHP显示错误。 Some environments can have this disabled by default.默认情况下,某些环境可以禁用此功能。

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.');
    }
}

确保安装了php5-mysql

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.那应该显示带有解析错误的文件和错误所在的行。

This behavior occurs when you have basic php syntax error in your code.当您的代码中有基本的 php 语法错误时,就会发生此行为。 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 解析器不会完全解析代码并且不显示任何内容,因此上述所有建议仅在您有语法错误以外的情况下才有效。

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.');
}
}

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.打开你的 php.ini。 Search and uncomment this line - extension=php_mysql.dll搜索并取消注释这一行 - extension=php_mysql.dll

    (Please also check If the PHP directive points to where your extensions is located. (另请检查 PHP 指令是否指向您的扩展程序所在的位置。
    Mine is extension_dir = "C:\\php-5.4.8-Win32-VC9-x86\\ext" )我的是extension_dir = "C:\\php-5.4.8-Win32-VC9-x86\\ext" )

  2. Restart Apache and refresh your page重启 Apache 并刷新页面

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 thatmodels and controllers's filenames should start with a uppercase letter .原来模型和控制器的文件名应该以大写字母开头

The file must be called 'Blog.php', with a capital 'B'.该文件必须命名为“Blog.php”,大写字母“B”。

Class names must start with an uppercase letter.类名必须以大写字母开头。

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.希望我有所帮助。

Make sure you don't have a blank index.html file in your root folder.确保根文件夹中没有空白的 index.html 文件。 It happens :)它发生了:)

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

error_reporting(E_ALL);

首先,您需要授予您的 Codeigniter 文件夹的权限,这可能是权限问题,然后启动您的服务器。

在您的index.php文件中添加以下行:

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

If you're using CI 2.0 or newer, you could change ENVIRONMENT type in your index.php to define('ENVIRONMENT', 'testing');如果您使用的是 CI 2.0 或更新版本,您可以将index.php ENVIRONMENT类型更改为define('ENVIRONMENT', 'testing'); . .
Alternatively, you could add php_flag display_errors on to your .htaccess file.或者,您可以将php_flag display_errors on添加到您的.htaccess文件中。

check if error_reporting is ON at server or not, if that id off you wont get any errors and just blank page.检查服务器上的 error_reporting 是否打开,如果该 ID 关闭,您将不会收到任何错误,只会出现空白页面。 if you are on a shared server then you can enable error reporting via htaccess.如果您在共享服务器上,则可以通过 htaccess 启用错误报告。 In codeIgniter add following in your htaccess在 codeIgniter 中,在您的 htaccess 中添加以下内容

php_flag display_errors On

and set并设置

error_reporting(E_ERROR); ## or what ever setting desired in php

hope it will work for you希望它对你有用

In system/core/Common.php there is an exception handler, with a block of code that looks like this:system/core/Common.php有一个异常处理程序,其代码块如下所示:

 // We don't bother with "strict" notices since they tend to fill up
 // the log file with excess information that isn't normally very helpful.
if ($severity == E_STRICT)
{
    return;
}

By removing the if and the return and the incorrect comment, I was able to get an error message, instead of just a blank page.通过删除ifreturn以及不正确的评论,我能够收到一条错误消息,而不仅仅是一个空白页。 This project isn't using the most recent version of CodeIgniter, hopefully they've fixed this bug by now.这个项目没有使用最新版本的 CodeIgniter,希望他们现在已经修复了这个错误。

load your url helper when you create a function eg,创建函数时加载您的 url 助手,例如,

visibility function_name () {

     $this->load->helper('url');
}

the it will show you errors or a view you loaded.它将显示错误或加载的视图。

Are you using the @ symbol anywhere?您是否在任何地方使用@ 符号?

If you have something like:如果你有类似的东西:

@include('page_with_error.php');

You will get a blank page.你会得到一个空白页。

I ran into this because I had a CLI running via cron as the root user, thus creating log files with root:root.我遇到了这个问题,因为我有一个通过 cron 以 root 用户身份运行的 CLI,从而使用 root:root 创建日志文件。 When you tried to navigate to a URI everything would work fine but CI exhibiting the blank page likely because it didn't have write permission to the log file.当您尝试导航到 URI 时,一切正常,但 CI 显示空白页可能是因为它没有对日志文件的写权限。

Codeigniter doesn't seem to throw an error message when I was referencing a view that did not exist.当我引用一个不存在的视图时,Codeigniter 似乎没有抛出错误消息。

In my example I had within my controller:在我的示例中,我的控制器中有:

$this->load->view('/admin/index/access_controls/groups/add');

Because the file did not exist, I got a blank "An error has occurred page".因为文件不存在,我得到一个空白的“发生错误页面”。 I changed the code to:我将代码更改为:

$this->load->view('/admin/access_controls/groups/add');

This was how I resolved the same issue you seem to be having, hope this helps someone some day.这就是我解决您似乎遇到的相同问题的方法,希望有一天能对某人有所帮助。

我也面临同样的问题并尝试了几乎所有的事情,但最后我重新启动了我的服务器,我发现一切都开始正常工作......我不知道如何......我认为这是一些服务器端问题,这就是为什么我的PHP CODE 没有给出任何错误。

If you have this in your php.ini:如果你的 php.ini 中有这个:

display_error = On;

and you have this in your CI Application at the same time并且您同时在 CI 应用程序中拥有它

error_reporting(0);

you'll get HTTP/1.1 200 OK and a completely bank page.你会得到 HTTP/1.1 200 OK 和一个完整的银行页面。

That's because when display_error is on, the php-fpm always return HTTP code 200. And all the errors to output are forbidden by error_reporting(0).那是因为当 display_error 开启时,php-fpm 总是返回 HTTP 代码 200。所有输出的错误都被 error_reporting(0) 禁止。

For CI application,the entry index.php sets up the running environment as bellows:对于 CI 应用,入口 index.php 设置运行环境如下:

if(isset($_SERVER['SERVER_ENV'])) {
    define('ENVIRONMENT', $_SERVER['SERVER_ENV']);
} else {
    define('ENVIRONMENT', 'development');
}

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

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

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

In short, when you set ENV directive in your webserver's conf,say Nginx's fastcgi_params:简而言之,当您在网络服务器的 conf 中设置 ENV 指令时,请说 Nginx 的 fastcgi_params:

fastcgi_param  SERVER_ENV         production;

then CI will automatically set然后CI会自动设置

error_reporting(0);

Another method is to see if you've surpassed the error checking in your code by accident.另一种方法是查看是否意外超出了代码中的错误检查。 Search all your code for any instance of error_reporting().在所有代码中搜索 error_reporting() 的任何实例。 If you call it without parameters, it just returns the current level, and is harmless.如果你不带参数调用它,它只会返回当前级别,并且是无害的。 If you call it with a parameter, such as 0 (zero), it will turn off error reporting.如果您使用参数调用它,例如 0(零),它将关闭错误报告。

You can test for this in CodeIgnitor by looking at their core library under ../system/core/Common.php and finding a section that's at about line 615 that looks like:您可以在 CodeIgnitor 中通过查看 ../system/core/Common.php 下的核心库并找到大约在第 615 行的部分,进行测试,如下所示:

if (($severity & error_reporting()) !== $severity)
{
   return;
} 

Add something like:添加如下内容:

if (($severity & error_reporting()) !== $severity)
{
   echo "Suppressing errors!";
   return;
} 

and you should be able to trap for surpassed errors, and debug from there.并且您应该能够捕获超出的错误,并从那里进行调试。

Often when codeigniter displays nothing, there is a syntax error.通常当 codeigniter 什么都不显示时,就会出现语法错误。 Mostly if the app was running seamlessly previously, just look around your most recent edits.大多数情况下,如果应用程序之前无缝运行,只需查看您最近的编辑。 For me the experience this time was the entire app, not just a page.对我来说,这次的体验是整个应用程序,而不仅仅是一个页面。 So I did a quick brain scan for the most recent edits I had done and worked backwards, reviewing each file I had worked on this day.因此,我对最近所做的编辑进行了快速的脑部扫描,然后向后工作,查看我今天处理的每个文件。 Turned out to be some 'where' clauses in two model files: For instance, I had结果是两个模型文件中的一些“where”子句:例如,我有

$this->db->where('Type' => 'Blog'); rather than $this->db->where('Type', 'Blog');

I was having same problem, i installed latest xamp version and found my site is not working, after research and wasting time i found that.我遇到了同样的问题,我安装了最新的 xamp 版本,发现我的网站无法正常工作,经过研究和浪费时间,我发现了这一点。

I need to turn on following tag in php.ini file short_open_tag=On我需要在 php.ini 文件中打开以下标签 short_open_tag=On

Make sure to restart apache after doing this.确保在执行此操作后重新启动 apache。

Hope this helps, most of these problems are related to php.ini file or fresh installation if your site was already running as other people facing similar issue.希望这会有所帮助,如果您的站点已经像其他面临类似问题的人一样运行,那么大多数这些问题都与 php.ini 文件或全新安装有关。

after installation of xamp/wamp you may notice few errors of similar nature.安装 xamp/wamp 后,您可能会注意到一些类似性质的错误。 If your website was already running dont worry, it is a configuration related issue.如果您的网站已经在运行,请不要担心,这是一个与配置相关的问题。

1) check database connections in database.php file inside application folder 2) check config.php file check url is correct or not? 1) 检查应用程序文件夹内 database.php 文件中的数据库连接 2) 检查 config.php 文件检查 url 是否正确? 3) by default short tags are off in new installations then follow the procedure below 3) 默认情况下,短标签在新安装中是关闭的,然后按照以下步骤操作

in php.ini file change "short_open_tag=Off" to "short_open_tag=On"在 php.ini 文件中将“short_open_tag=Off”更改为“short_open_tag=On”

Make sure to restart apache after doing this.确保在执行此操作后重新启动 apache。

hope this helps.希望这可以帮助。

就我而言,发生错误是因为我的 Apache 服务器配置为以Fast CGI运行PHP ,我将其更改为FPM并且可以正常工作。

Just for anyone who is still looking for answers:仅适用于仍在寻找答案的任何人:

$db['default']['dbdriver'] = 'mysqli'; $db['default']['dbdriver'] = 'mysqli'; (make sure you use mysqli, not mysql). (确保您使用 mysqli,而不是 mysql)。 (database.php) (数据库.php)

If you get net::ERR_CONTENT_DECODING_FAILED in the console then you are using gzip in your .htaccess file but gzip encoding is Off.如果您在控制台中看到 net::ERR_CONTENT_DECODING_FAILED,那么您在 .htaccess 文件中使用了 gzip,但 gzip 编码处于关闭状态。

Enable zlib.output_compression=On in php.ini and restart Apachephp.ini启用zlib.output_compression=On并重新启动 Apache

请检查错误文件夹是否在应用程序文件夹中,而不是在我的情况下我替换应用程序文件夹中的错误文件夹

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM