2

私は学習プロセスとして独自のフレームワークを作成しています。フレームワークが開発モードであるかどうかを設定できる構成ファイルがあります。

<?PHP
$project[security][dev_mode] = true;
?>

Display_startup_errorsは.htaccessで定義され、構文エラーを表示する必要があるかどうかを示します。ユーザーが.htaccessファイルをいじる必要がない場合は、構成ファイルの設定に「調整」することをお勧めします。.htaccessにphpファイルの内容をチェックさせ、それに応じて行動させることができるかどうか、そしてどのようにできるの、誰かが考えましたか?

.htaccess以外の方法でdisplay_startup_errorsを設定するソリューションも歓迎します;-)。

よろしくお願いします!

4

2 に答える 2

1

試す

<?php
$iDevMode = ( $project['security']['dev_mode'] ) ? 1 : 0;

ini_set('display_errors', $iDevMode);
?>

定義に基づいて切り替えます。これは醜い三項演算であり(練習のためにifステートメントに変換できます)、プログラムの非常に早い段階で処理する必要があります。

また、上記のように、PHPは連想配列参照を引用符で囲まないように通知をスローすることにも注意してください。

于 2013-03-27T00:58:20.873 に答える
1

エラーの処理に.htaccessを使用する別の方法は、他のフレームワークと同じように、開発、本番、テストの段階で設定できる構成可能なphpファイルを作成することです。

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

または、手動でini_set()を使用して、エラー処理の構成をオンに適切に設定してみてください

// change settings for error handler to show errors
// $this setup is used for checking errors for development to be shown.... 
ini_set('display_errors', 1);
ini_set('display_startup_errors',1);
error_reporting(E_ALL);
于 2013-03-27T01:07:34.790 に答える