6

I'm new to Magento and I have a config.xml which stands for a module configuration as far as I've learned.

I have problems to understand (also to locate some sort of documentation for that, Magentos config.xml Reference is totally no-saying to me) on this very basic level already. For example the following excerpt from config.xml:

<?xml version="1.0"?>
<config>
    <modules>
        <My_Mage>
            <version>1.0.0</version>
        </My_Mage>
    </modules>
    <global>
        <models>
            <My_Mage>
                <class>My_Mage_Model</class>
            </My_Mage>
            <!-- ... --->
        </models>
    </global>
</config>

What is the part in config/globals/models about?

I guessed it was about some file on disk, however I can not find any file related to the <class> "My_Mage_Model".

For what does that part stand for?:

        <models>
            <My_Mage>
                <class>My_Mage_Model</class>
            </My_Mage>

Any hints greatly appreceated.

hakre
  • 2,831
  • 4
  • 27
  • 50
  • Looks like this is the base class name for all the models in that module. It means, that all model class names are prefixed with it (e.g. class My_Mage_Model_ConcreteModel). The module name is given within the <My_Mage> tag, corresponding to the module directory. See https://magento.stackexchange.com/questions/18269/understanding-config-xml-what-is-configglobalmodelsmy-mage - Still not sure about <globals>. – hakre Apr 11 '14 at 14:17
  • 1
    means all things that are used globally, e.g. helper-, block- and model-classes, in comparison to things used only for or , e.g. observers or layout updates. If you search the web for material on how to create an own extension, many of these things will be explained. <My_Mage> is technically not only the class name, but also the module's name and the name of the directories your files are in. – simonthesorcerer Apr 11 '14 at 19:28
  • @simonthesorcerer: Thanks for your comment, if you can suggest a good developer resource for modules and magento online, your sharing is highly appreceated. I have problems to find distinct resources via google, the knowledge base article I linked was a good relief, so suggestions welcome in case you know a snappy one. – hakre Apr 14 '14 at 09:13
  • 1
    Hi hakre, is this what you are searching for? http://info.magento.com/rs/magentocommerce/images/Magento-Extension-Developers-Guide-v1.0.pdf There is also the MagentoU-portal, where you can watch about 40h video material for free – simonthesorcerer Apr 16 '14 at 18:40
  • @simonthesorcerer this looks very good. On Magento U I didn't found any freely accessible videos, I guess it needs some account but I don't have mine on this computer right now, so will give it a try mid next week. Thanks a lot! – hakre Apr 17 '14 at 17:45

2 Answers2

2

The node that contains <class>My_Mage_Model</class> registers all classes prefixed with My_Mage_Model as models that can be utilized using the Mage::getModel method. There is most likely a directory at <root>/app/code/local/My/Mage/Model/ and this is where you put any models for the "My" module.

If you were going to write a helper class for this module you would follow the same pattern - put the class in <root>/app/code/local/My/Mage/Helper/ and add a node within <global> like

<helper>
  <My_Mage>
    <class>My_Mage_Helper</class>
  </My_Mage>
 </helper>
DSG
  • 423
  • 1
  • 3
  • 6
2

<global> node contains definations that should be shared between all scopes (admin, frontend, adminhtml, default)
<models> node is used for declaring models in your module.
<My_Mage> is a unique string to model declaration of your module. But mostly we are using here is Namespace_Modulename as it is also unique.
<class> node contains the path to your models folder of this particular module.

Magento will traverse in your module's model folder as app/code/codePool/My(Namespace)/Mage(Modulename)/Models

Modules's declaration is done in <modules> node.

>     <modules>
>         <My_Mage(Namespace_Modulename)> // app/code/codePool/Namespace/Modulename
>             <version>1.0.0</version>
>         </My_Mage>
>     </modules>
Anshu Mishra
  • 8,950
  • 7
  • 40
  • 88