Php 在zend framework 2中隐藏数据库密码

Php 在zend framework 2中隐藏数据库密码,php,doctrine-orm,zend-framework2,database-security,Php,Doctrine Orm,Zend Framework2,Database Security,我有一个利用doctrine2的zend项目 我的问题是我不能禁用敏感数据的错误。i、 e.当数据库连接失败时,会显示一个错误,包括密码 到目前为止,我尝试将公用文件夹中的index.php文件更改如下: <?php //Disable all error reporting error_reporting(0); //Somehow this doesn't work ini_set('display_errors', false); //Somehow this doesn't wor

我有一个利用doctrine2的zend项目

我的问题是我不能禁用敏感数据的错误。i、 e.当数据库连接失败时,会显示一个错误,包括密码

到目前为止,我尝试将公用文件夹中的index.php文件更改如下:

<?php
//Disable all error reporting
error_reporting(0); //Somehow this doesn't work
ini_set('display_errors', false); //Somehow this doesn't work
/**
 * This makes our life easier when dealing with paths. Everything is relative
 * to the application root now.
 */
chdir(dirname(__DIR__));

// Decline static file requests back to the PHP built-in webserver
if (php_sapi_name() === 'cli-server' && is_file(__DIR__ . parse_url($_SERVER['REQUEST_URI'], PHP_URL_PATH))) {
    return false;
}

// Setup autoloading
require 'init_autoloader.php';

// Run the application!
try{
Zend\Mvc\Application::init(require 'config/application.config.php')->run();
}
catch(Exception $ex){
    echo 'server error!';//This code is never reached although a PDOException is thrown!
}

我需要做什么才能禁用此类错误并隐藏敏感数据?

编辑:没有发现这是ZEND 2。见下面我最后的评论

我猜错误级别报告是用这一行设置的

Zend\Mvc\Application::init(require 'config/application.config.php')->run();
这是在你关掉它之后,所以它只是被重新打开

在application.ini中尝试此操作

phpSettings.display_startup_errors = 0
phpSettings.display_errors = 0
resources.frontController.throwExceptions = 0
resources.frontController.params.displayExceptions = 0

似乎我必须更改我的项目文件夹/module/Application/config/module.config.php中的视图管理器配置,方法是将display\u exceptions设置为false:

'view_manager' => array(
        'display_not_found_reason' => true,
        'display_exceptions'       => false, //This line did the trick!
        'doctype'                  => 'HTML5',
        'not_found_template'       => 'error/404',
        'exception_template'       => 'error/index',
        'template_map' => array(
            'layout/layout'           => __DIR__ . '/../view/layout/layout.phtml',
            'application/index/index' => __DIR__ . '/../view/application/index/index.phtml',
            'error/404'               => __DIR__ . '/../view/error/404.phtml',
            'error/index'             => __DIR__ . '/../view/error/index.phtml',
        ),
        'template_path_stack' => array(
            __DIR__ . '/../view',
        ),
    ),
查看此->特别是警告通知

在索引文件中使用Try/Catch不适合您。您需要将其放入您的服务层,或者您在没有提供此代码示例的情况下执行DB查询的任何地方

您还可以在module.config.php文件集中:

'display_exceptions' => false

另外,请注意您使用的异常处理程序,因为不同的异常处理程序可能返回不同的信息。

我找不到application.ini文件,该文件位于何处?应该位于您的\u项目\u文件夹/application/configs/application.ini中我没有application/configs/application.ini文件。我想这只适用于zend framework 1。啊。。。错过了。在这种情况下,我不知道。看起来Zend 2的配置不同。看看这个问题-