PHP错误弄乱网站外观

时间:2012-05-10 22:19:54

标签: php codeigniter error-handling

我有一个主要用php构建的网站。我有的问题是在顶部我有一个背景图像的div。它必须在一个非常具体的地方。每次出现PHP错误时,div都会向下移动,这会使页面看起来很糟糕。

我可以想到两个可能的解决方案,但我不知道如何做到这一点,搜索网络是一项徒劳无功的努力。

  • 让它如此php错误不会将div推下来(我尝试浮动但是div中有其他东西需要在左侧,而图像在右侧)

    < / LI>
  • 让php错误出现在别处。 (我不知道怎么做,也找不到任何东西)

我正在使用codeigniter。谢谢你的帮助。

5 个答案:

答案 0 :(得分:4)

您使用的平台无关紧要,但后端的错误应始终写入日志文件而不是生产中输出。这就是你在PHP中的表现:

答案 1 :(得分:2)

答案是您永远不会在生产服务器上显示PHP错误。您只应在实时服务器上显示它们。

因此,在测试和构建应用程序时,错误出现的位置无关紧要。

但是在你的实时服务器上,你需要隐藏php错误,同时仍然记录。 Codeignitier提供这种能力。

首先,在index.php中更改

define('ENVIRONMENT', 'development');

 if ($_SERVER['SERVER_NAME'] == 'localhost')
 {
define('ENVIRONMENT', 'development');
 }
 else
 {
define('ENVIRONMENT', 'production');
 }

这将自动设置您在本地主机上的开发模式,以及部署时的生产模式(即没有代码更改)。

现在根据需要配置一些内容:

inside Index.php also change the error reporting to:
if (defined('ENVIRONMENT'))
{
    switch (ENVIRONMENT)
    {
        case 'development':
            error_reporting(-1);
        break;

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

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


 Config.php
 // Set logs to show Debug + Error messages on your development
 // But only error messages on your production server
 $config['log_threshold'] = (ENVIRONMENT == 'development' ? '2' : '1');


 Database.php (config)
 $active_record = TRUE;
 $active_group = (ENVIRONMENT == 'development' ? 'localdev' : 'production');
 // Now define the two different groups here, making sure production has:
 $db['production']['db_debug'] = FALSE;

答案 2 :(得分:1)

最明显的答案是确保没有错误。 如果无法做到这一点,请将以下行添加到PHP脚本中:

error_reporting ('E_NONE');

答案 3 :(得分:1)

以上所有答案都是生成PHP CodeIgniter代码的正确方法。

但要回答您的问题,如果您有个人偏好,则可能需要在定义图像css时尝试使用z-index属性。

它不会降低您的错误,但如果图像的z-index高于包含错误的div的z-index,则图像将始终位于您修复的位置。

https://developer.mozilla.org/en/CSS/Understanding_z-index

答案 4 :(得分:0)

一个快速修复方法是在<?php开头标记下方的代码下方插入

<?php

error_reporting(0); // this will prevent the errors from showing

ini_set('log_errors', 1); // this will log the errors in the log file.

希望这会有所帮助。

相关问题