How to get magento backend xml file data?

There is system.xml in my module that starts with this:

<config>
    <sections>
        <dev>
            <groups>
                <my_module>
                    <label>...

I want to get the value of this label from another module. How should I do it? My first thought was Mage::getConfig('sections/dev/groups/my_module/label'), but it did not work - it seems that the <sections>configuration area is inaccessible. I also cannot figure out where magento is loading this value, which he must make at some point, or he will not be able to display it.

To be completely clear: I am not trying to get the value of the configuration data that is stored in the core_config_data table, which does not cause problems. I want to be able to get other attributes related to it - for example, a group label or sort order of fields, and for this I need to be able to read the <sections>configuration area .

+5
source share
2 answers

Files system.xmlnever merge with global configuration. They only load when Magento creates a user interface for

System -> Configuration 

backend admin applications. In addition, the application does not use them.

If you want to capture a shortcut, you will need to download the full configuration system.xmlyourself. Something like this should work.

//load and merge `system.xml` files
$config = Mage::getConfig()->loadModulesConfiguration('system.xml');        

//grab entire <sections/> node
var_dump($config->getNode('sections')->asXml());        

//grab label from a specific option group as a string
var_dump((string)$config->getNode('sections/dev/groups/restrict/label'));

As mentioned in another answer in this thread, there is also a model class adminhtml/configthat wraps part of this logic in the method getSection, so you can do something like this.

Mage::getSingleton('adminhtml/config')->getSection('dev')->groups->my_module->label

If you look at the source getSection

#File: app/code/core/Mage/Adminhtml/Model/Config.php
public function getSections($sectionCode=null, $websiteCode=null, $storeCode=null)
{
    if (empty($this->_sections)) {
        $this->_initSectionsAndTabs();
    }

    return $this->_sections;
}

and follow the call stack until _initSectionsAndTabs

#File: app/code/core/Mage/Adminhtml/Model/Config.php
protected function _initSectionsAndTabs()
{
    $config = Mage::getConfig()->loadModulesConfiguration('system.xml')
        ->applyExtends();

    Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));
    $this->_sections = $config->getNode('sections');
    $this->_tabs = $config->getNode('tabs');
}

, loadModulesConfiguration. applyExtends, , , . (self-links, StackOverflow).

, , - ,

Mage::dispatchEvent('adminhtml_init_system_config', array('config' => $config));

, , . XML. , , . , .

+6

, ...

/dev/my _module/label:

Mage::getSingleton('adminhtml/config')->getSection('dev')->groups->my_module->label

, Mage::getSingleton('adminhtml/config')->getSection('dev'), ( ->getSections(), ). Mage_Core_Model_Config_Element, , , . print_r , , print_r, , .

+2

All Articles