5

I am new into Magento development, I have created some basic modules also with the help of available tutorials. However, I am not able to understand the difference between <module>...</module> & <namespace_module>...</namespace_module>. Most of the time I saw in config.xml.

For example, I am creating a module Vaibhav_Customproduct under this module I am going to create a Model folder inside that Customproduct.php class.

Now, if I have to declare my model in config.xml I have seen in 2 different ways. I just want to understand the difference between below to declaration type.

Example 1

    <models>
        <Customproduct>
            <class>Vaibhav_Customproduct_Model</class>
        </Customproduct>
    </models>

Example 2

    <models>
        <Vaibhav_Customproduct>
            <class>Vaibhav_Customproduct_Model</class>
        </Vaibhav_Customproduct>
    </models>
7

The difference between them are Customproduct and Vaibhav_Customproduct. Those are unique identifier for your model declaration.

Mage::getModel('UNIQUE_IDENTIFIER/model'); 

The unique identifier which you have declared in your config.xml is only used to call your model.

In your case, to call your model you use below two method.

If you used unique identifier Customproduct then you can call your model like following

Mage::getModel('Customproduct/model');

For unique identifier Vaibhav_Customproduct, you can call your model like following

Mage::getModel('Vaibhav_Customproduct/model');

From here, you can see that all model whose name begins with Vaibhav_Customproduct_Model are defined within Model folder of this module. Second part of Vaibhav_Customproduct/model OR Customproduct/model is telling Magento in which file is class defined. And in this case, it is Model.php

Hope this make sense to you.

  • 2
    As it is conceivable that another extensions also adds a "Customproduct" I would suggest going with the approach in Example 2 to avoid one area of possible conflict. – Kristof at Fooman Mar 3 '16 at 5:55
  • Thank @KristofatFooman I am following the same convention. :-) – Vaibhav Dass Mar 3 '16 at 5:58
  • Hey @Rohit can I have your skype id. So that, I can ask you few questions directly. – Vaibhav Dass Mar 3 '16 at 6:18
  • Go through my website. contact me there – Rohit Kundale Mar 3 '16 at 6:30
  • @Rohit Error sending message, please try again! on your website – Vaibhav Dass Mar 3 '16 at 9:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.