Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8869867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T17:34:58+00:00 2026-06-14T17:34:58+00:00

Currently I am loading multiple config files containing PHP native arrays, within my bootstrap.

  • 0

Currently I am loading multiple config files containing PHP native arrays, within my bootstrap.

require "app/configuration/config-global.php";
require "app/configuration/config-other.php";

With this setup "config-other.php" is overwriting the $settings array of "config-global.php".

Could I please get some advice on the best way to append the array within my bootstrap please.

Tim

Update

Here is a cut down version of my bootstap file setup attempting to implement Nikolaos’s suggestion.

class Application extends \Phalcon\Mvc\Application
{

    /**
     * Register the services here to make them general or register in the ModuleDefinition to make them module-specific
     */
    public function _registerServices()
    {

        //Define constants
        $di = new \Phalcon\DI\FactoryDefault();

        $loader = new \Phalcon\Loader();

        $di->set('registry', function () {
            return new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        });

        //load our config into the registry
        //$di->set('config', $config);

        $this->setDI($di);
    }

    public function _loadConfig()
    {

        $di = \Phalcon\DI::getDefault();

        $this->processConfig('appConfig1');
        $this->processConfig('globalConfig');

        // Remember config_array is the merged array in the DI container
        $new_array = $di->registry->offsetGet('config_array');

        // Optional, store the config in your DI container for easier use
        $di->set('config', function () use ($new_array) {
                return new \Phalcon\Config($config);
            }
        );

    }

    public function main()
    {

        $this->_registerServices();
        $this->_loadConfig();

        echo $this->handle()->getContent();
    }

    public function processConfig($name)
    {

    $config = array();
    $di     = \Phalcon\DI::getDefault();

    if ($di->registry->offsetExists('config_array'))
    {
        $config = $di->registry->offsetGet('config_array');
    }

    // Now get the file from the config
    require "/config/{$name}.php";

    // $settings came from the previous require
    $new_config = array_merge($config, $settings);

    // Store it in the DI container
    $di->registry->offsetSet('config_array', $new_config);

    }

}

$application = new Application();
$application->main();

With the above config I get:

[02-Dec-2012 09:10:43] PHP Notice: Undefined property:
Phalcon\DI\FactoryDefault::$registry in /public/frontend/index.php on
line 127

[02-Dec-2012 09:10:43] PHP Fatal error: Call to a member
function offsetExists() on a non-object in /public/frontend/index.php
on line 127

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T17:34:59+00:00Added an answer on June 14, 2026 at 5:34 pm

    Try this:

    Register a new service in the DI container

    // Get the DI container
    $di = \Phalcon\DI::getDefault();
    
    $di->set(
        'registry', 
        function ()
        {
            return new ArrayObject(array(), ArrayObject::ARRAY_AS_PROPS);
        }
    );
    

    The above will be the “registry” that we will store the configuration files.

    public function processConfig($name)
    {
        $config = array();
        $di     = \Phalcon\DI::getDefault();
    
        if ($di->registry->offsetExists('config_array'))
        {
            $config = $di->registry->offsetGet('config_array');
        }
    
        // Now get the file from the config
        require ROOT_PATH . "app/configuration/{$name}.php";
    
        // $settings came from the previous require
        $new_config = array_merge($config, $settings);
    
        // Store it in the DI container
        $di->registry->offsetSet('config_array', $new_config);
    }
    

    And as usage you can do this:

    processConfig('config-global');
    processConfig('config-other');
    
    // Remember config_array is the merged array in the DI container
    $di = \Phalcon\DI::getDefault();
    
    // Remember config_array is the merged array in the DI container
    $new_array = $di->registry->offsetGet('config_array');
    
    // Optional, store the config in your DI container for easier use
    $di->set(
        'config', 
        function () use ($new_array)
        {
            return new \Phalcon\Config($config);
        }
    };
    

    The config array in the container now has the merged data.

    You can also create a class that would encapsulate that functionality and have other helper functions in there to clear the DI container reference, to load the base array (global) all the time etc.

    EDIT: Modified it slightly after comments

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have added multiple app.config (each with a differet name) files to a project,
We have a Flex app that is currently loading an XML file that contains
I'm currently working on a small project where I'm loading 16bit wave files with
I'm loading multiple swf files from the main menu which is never unloaded. I've
I currently use a lot of perl binary hash files stored in multiple file
Currently I am loading data from a previous session into my application using the
Currently,I know how to do a lazy implementation of the loading procedure of the
I am currently looking at jQuery mobile and its system of loading web pages
We're currently using folders inside webroot to store images and videos which we're loading
I'm loading layers of images to make a single image. I'm currently stacking them

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.