We started explaining how Magento loads and manipulates configuration information here.
The next step is writing config into cache, if it is enabled.
Our configuration is formed by now, but besides compiling this .xml file, we need to obtain data from it somehow. Let’s go back to Mage.php.
Here are the methods:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
<?php /** * Retrieve config value for store by path * * @param string $path * @param mixed $store * @return mixed */ public static function getStoreConfig($path, $store = null) { return self::app()->getStore($store)->getConfig($path); } /** * Retrieve config flag for store by path * * @param string $path * @param mixed $store * @return bool */ public static function getStoreConfigFlag($path, $store = null) { $flag = strtolower(self::getStoreConfig($path, $store)); if (!empty($flag) && 'false' !== $flag) { return true; } else { return false; } } |
Their only difference is that getStoreConfig() will return the exact value while getStoreConfigFlag(), as its name suggests, returns boolean true or false. Both methods send us to Mage_Core_Model_Store::getConfig()
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php /** * Retrieve store configuration data * * @param string $path * @return string|null */ public function getConfig($path) { if (isset($this->_configCache[$path])) { return $this->_configCache[$path]; } $config = Mage::getConfig(); $fullPath = 'stores/' . $this->getCode() . '/' . $path; $data = $config->getNode($fullPath); if (!$data && !Mage::isInstalled()) { $data = $config->getNode('default/' . $path); } if (!$data) { return null; } return $this->_processConfigValue($fullPath, $path, $data); } |
If the requested information is not found in a local cache, this method will use the path stores/[store code]/[requested path]. If data is still not found, the method will use another path default/[requested path] to search in the loaded configuration. When nothing is found, method will return null.
Found data is processed via _processConfigValue() method:
• If the returned node has children, data will be stored in a local cache recursively. By the next call within a current user session there will be no need to look for a found data in the configuration.
• If the node has backend_model, this model should be requested to bring data to the required format.
• Variable of {{unsecure_base_url}}, {{unsecure_base_url}}, {{base_url}}sort are replaced by the correspondent values.
Magento 2 Development
Take your online store to the next level with BelVG Magento 2 Development
Visit the pageAs a conclusion I would like to sum everything up and point out the basics.
1. All .xml files are collected into one big simpleXmlElement object
2. First, data is loaded from app/etc/*.xml and then from app/etc/modules/*.xml. Based on the module loaded information, config.xml is loaded from the etc directory of the module. If we load backend to check ACL and build menu elements, adminhtml.xml and system.xml are loaded as well. Configuration data from the database is the last one to load.
3. Any parameters, except the ones stored in app/etc/local.xml, can be overridden in config.xml of a custom module.
P.S. Even though Magento provides us with such convenient methods as Mage:: getStoreConfig() and Mage:: getStoreConfigFlag(), we can reach any element of the configuration tree with the help of Mage::getConfig()->getNode($path, $scope, $scopeCode);
Look at your final config of the Magento installation by running the following piece of code in the site root directory:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?php define('MAGENTO_ROOT', getcwd()); $mageFilename = MAGENTO_ROOT . '/app/Mage.php'; require_once $mageFilename; umask(0); /* Store or website code */ $mageRunCode = isset($_SERVER['MAGE_RUN_CODE']) ? $_SERVER['MAGE_RUN_CODE'] : ''; /* Run store or run website */ $mageRunType = isset($_SERVER['MAGE_RUN_TYPE']) ? $_SERVER['MAGE_RUN_TYPE'] : 'store'; Mage::app($mageRunCode, $mageRunType); $config = Mage::getConfig()->getNode()->asXml(); file_put_contents('config.xml', $config); |
Read our previous posts.
Class Naming Conventions and Their Relationship with the Autoloader
The Main Magento Design Areas and More…
Magento Custom Development
Take your online store to the next level with BelVG Magento Custom Development
Visit the page
Yeah,
So long, Pavel does my half MDC ;-)
Thanks for your great tutorials!
Thanks pavel,
Its very helpful post. I am working on magento since 4 yrs. but don’t know this things. Thank you so much for such a useful post.
This is good news for our magento developer have new challenging question Explaining how Magento Loads and Manipulates Configuration Information.