Answer

There is no native support for that in zf2 (afaik). You'd either have to set them in php.ini itself, or set them in index.php

<?php
error_reporting(E_ALL);
ini_set('display_errors', true);

If you really want to be able to supply them as config settings, you could keep what you have and do that in a module bootstrap, get them from config, and call ini_set() on each key value pair

public function onBootstrap(EventInterface $e) {
    $app = $e->getApplication();
    $sm = $app->getServiceManager();
    $config = $sm->get('Config');
    $phpSettings = isset($config['phpSettings']) ? $config['phpSettings'] : array();
    if(!empty($phpSettings)) {
        foreach($phpSettings as $key => $value) {
            ini_set($key, $value);
        }
    }
}

Edit: as @akond rightly points out in the comments, you could just add the ini_set lines to local.php which is a better solution.

  • 8
Reply Report
      • 1
    • @akond +1 you're quite correct, that's a better option, the bootstrap code's there just to demonstrate how to make what the OP has work.
      • 2
    • If you put the lines in local.php, you may miss errors that occur before it tries to load this file. I found I had to put the lines in index.php
      • 1
    • There is no need for this long onBoostrap code. He could just put error_reporting in the config file itself, since it is a PHP file.

To easilly configure phpSettings on your ZF2 app, you should consider using DluPhpSettings.

With this module, you can configure your settings for each environment you have:

/* Local application configuration in /config/autoload/phpsettings.local.php */
<?php
return array(
    'phpSettings'   => array(
        'display_startup_errors'        => false,
        'display_errors'                => false,
        'max_execution_time'            => 60,
        'date.timezone'                 => 'Europe/Prague',
        'mbstring.internal_encoding'    => 'UTF-8',
    ),
);

Look this blog post for more info too!

  • 6
Reply Report

Warm tip !!!

This article is reproduced from Stack Exchange / Stack Overflow, please click

Trending Tags

Related Questions