Good day, habrasoobschestvo.
This is my first article, so do not judge strictly. For several years I have been developing online stores based on Magento. During this time, I have accumulated a lot of information regarding the work of this platform, which is impossible to keep in my head forever, so I decided to structure it as a series of articles.
Who cares, welcome under cat.
Any access to the pages in the online store based on Magento begins with processing index.php. This file performs a primary check, including the PHP version, declares constants and connects the Mage.php file with the base class Mage. This class implements a lot of interesting methods, which will be discussed later in the article, but at the moment we are interested in the method
run, responsible for the launch of the store. To understand how the configuration files are loaded, consider this method:
self::$_app = new Mage_Core_Model_App(); if (isset($options['request'])) { self::$_app->setRequest($options['request']); } if (isset($options['response'])) { self::$_app->setResponse($options['response']); } self::$_events = new Varien_Event_Collection(); self::_setIsInstalled($options); self::_setConfigModel($options); self::$_app->run(array( 'scope_code' => $code, 'scope_type' => $type, 'options' => $options, ));
It can be seen that the method creates a new class Mage_Core_Model_App and calls the run method for it, where the methods of initial loading the configuration files are called.
Consider this method:
public function run($params) { $options = isset($params['options']) ? $params['options'] : array(); $this->baseInit($options); Mage::register('application_params', $params); if ($this->_cache->processRequest()) { $this->getResponse()->sendResponse(); } else { $this->_initModules(); $this->loadAreaPart(Mage_Core_Model_App_Area::AREA_GLOBAL, Mage_Core_Model_App_Area::PART_EVENTS); if ($this->_config->isLocalConfigLoaded()) { $scopeCode = isset($params['scope_code']) ? $params['scope_code'] : ''; $scopeType = isset($params['scope_type']) ? $params['scope_type'] : 'store'; $this->_initCurrentStore($scopeCode, $scopeType); $this->_initRequest(); Mage_Core_Model_Resource_Setup::applyAllDataUpdates(); } $this->getFrontController()->dispatch(); } return $this; }
The baseInit method is responsible for initializing the _config property and loading basic configurations. The base configuration is loaded in the _initBaseConfig method, which later calls the loadBase method from the Mage_Core_Model_Config class.
The loadBase method parses and saves the data from app / etc / local.xml and app / etc / config.xml to the _xml property of the Mage_Core_Model_Config object. These files contain access to the database and the basic settings of the online store.
After that, the module configuration files are loaded. The _initModules method, which, in turn, calls the loadModules method from the Mage_Core_Model_Config class, is responsible for this.
To load the module configuration files, first load a list of all files from the app / etc / modules folder and parse these files. The _loadDeclaredModules method is responsible for this. In the loadModules method, only two types of files from the etc folder in the module directory are processed:
- 1. confix.xml
- 2. config. {Resource_name} .xml (in our case, config.mysql4.xml)
To load them, the loadModulesConfiguration method is called, to which, as $ fileName, an array with file names is passed (config.xml and config.mysql4.xml)

Next, parsing and data loading into the _xml property is performed for all active modules:
$modules = $this->getNode('modules')->children(); foreach ($modules as $modName=>$module) { if ($module->is('active')) { if ($disableLocalModules && ('local' === (string)$module->codePool)) { continue; } if (!is_array($fileName)) { $fileName = array($fileName); } foreach ($fileName as $configFile) { $configFile = $this->getModuleDir('etc', $modName).DS.$configFile; if ($mergeModel->loadFile($configFile)) { $mergeToObject->extend($mergeModel, true); } } } }
Using the local.xml file, you can make your changes to the basic configuration of the online store.
This completes the loading of the configuration, and the corresponding processes are launched, depending on the router of the page to which you switched.
')
Thank you for your attention, I look forward to your criticism.