0

How to properly create a custom configuration key in zend expressive I tried to create a file custom-config.php in the config/autoload directory but the key is not read by the container

my custom-config.php looks like this

<?php
[
    'customkey' => [
    'value1' => '1',
    'value2' => '2',
    ],
];
Bram Gerritsen
  • 7,178
  • 4
  • 35
  • 45
metamp_mvc
  • 65
  • 10

3 Answers3

2

I think you a missing a return statement.

Try with

<?php

return [
    'customkey' => [
        'value1' => '1',
        'value2' => '2',
    ],
];
marcosh
  • 8,780
  • 5
  • 44
  • 74
1

Besides missing return statement, as marcosh pointed out, I think additional problem is the filename itself.

It should be something like custom-config.local.php or custom-config.global.php.

  • I corrected both the file name and the return statement so it's reading the config file fine now. Thank you all – metamp_mvc Jun 11 '16 at 04:10
1

Configuration files are loaded in a specific order. First global.php, then *.global.php, local.php and finally *.local.php. This way local settings overwrite global settings.

Settings shared between servers go into *.global.php, sensitive data and local settings in *.local.php. Local config files are ignored by git.

The default loading behavior is set in config/config.php if you want to change this.

Your custom config could look like this:

<?php // config/autoload/custom-config.global.php

return [
    'dependencies' => [
        'invokables' => [
            // ...
        ],
        'factories' => [
            // ...
        ],
    ],
    // Prefered format
    'vendor' => [
        'package' => [
            'key' => 'value',
        ]
    ],
    // Custom package
    'custom_package' => [
        'value1' => '1',
        'value2' => '2',
    ],
];
xtreamwayz
  • 1,285
  • 8
  • 10