Magento XML files

Magento

Magento keeps a lot of configurations in xml files.

For example:

1. Activation of a module

2. Module configuration

3. Layout configurations

The most simple example are xml files for module activation and look like this:

<!--?xml version="1.0"?-->
    <config>
        <modules>
            <namespace_mymodule>
                <active>true</active>
                <codepool>local</codepool>
                <depends>
                    <mage_core>
                    <mage_catalog>
                </mage_catalog></mage_core></depends>
            </namespace_mymodule>
        </modules>
    </config>

Tag active can have to possible values: true or false. If is set to true module is active, and if is set to false, or this xml not exist, module is disabled and it will not be loaded by magento.

Tag codePool it tell to magento in wich folder module is located. Possible values are local (ussually), community, or core.

Tags depends is optional and tells magento that module is dependend of other modules, and that module must exist and active. Next category of magento xml file types are module xml configuration files. Below is an example:

<!--?xml version="1.0"?-->
<config>
    <modules>
        <namespace_mymodule>
            <version>0.1.0</version>
        </namespace_mymodule>
    </modules>
    <global>
        <models>
            <namespace_mymodule>
                <class>Namespace_MyModule_Model</class>
            </namespace_mymodule>          
        </models>  
        <blocks>
            <namespace_mymodule>
                <class>Namespace_MyModule_Block</class>
            </namespace_mymodule>
        </blocks>
        <helpers>
            <namespace_mymodule>
                <class>Namespace_MyModule_Helper</class>
            </namespace_mymodule>
        </helpers>
    </global>
</config>

Each magento module must have in module folder structure, under etc directory, at least one xml file configuration, like one listed above, if configuration file not exist magento will not know what to load from our module.

Tag config represents root node for magento module configuration. Under tags modules ca be defined module version, and is optional especially if our module hasn't an install script.

Under the global tag we define configurations for global scope. In this example we define configurations for model, blocks and helpers. Under this tags usually, we defined how our modules, blocks and helper can be called from other any part of magento code, or we define what models, blocks and helper want to rewrite and with and with whom. This config file can be more complex, but for this example i thing that is best to use a simplified one. Next type of magento xml configuration are layout's configurations files, like this one:

<!--?xml version="1.0"?-->
<layout version="0.1.0">
    <default>
    </default>
    <namespace_mymodule_index_index>
         <reference name="root">
            <action method="setTemplate"><template>page/2columns-left.phtml</template></action>
        </reference>
        <reference name="content">
            <block name="myblock" template="mymodule/myblock.phtml" type="namespace_mymodule/myblock">
        </block></reference>
    </namespace_mymodule_index_index>
</layout>

In this configuration module we define an custom handler for our module named "namespace_mymodule_index_index" and when this handler is called it will set a certain type of template and in content section it will render myblock content. This was a short introduction in magento xml config files. I hope in the future to write an dedicated article for each type of those files.


Add comment
 
 
 

Comments