2

I constantly get into a personal dilemma about how to use group names in my models/helpers etc

Should I be camel casing my block, helper, model group names in config xml?

Say i have a namespace/module like so:

Me_MyModule

should my config xml look like this for the models section:

<models>
    <me_myModule>
        <class>Me_MyModule_Model</class>
    </me_myModule>
</models>

which would mean creating models like so:

Mage::getModel('me_myModule/the_model_name');

or should i stick to all lower case? i.e.:

<models>
    <me_mymodule>
        <class>Me_MyModule_Model</class>
    </me_mymodule>
</models>

or even omit the namespace (again with the camel case / no camel case dilemma:

<models>
    <myModule>
        <class>Me_MyModule_Model</class>
    </myModule>
</models>
Marty Wallace
  • 5,631
  • 13
  • 65
  • 90

1 Answers1

5

Again, there's no official guidelines on this, but I try to keep these class aliases all lowercase, my logic being something like

  1. Ideally, these shouldn't be case sensitive, because that leads to subtle capitalization errors and human programmers want to treat catalog and Catalog as the same word)

  2. So, since I can't have them case insensitive, I'll leave them all one case, making the rules simple.

  3. And lowercase is easier to read than uppercase

Also, (I believe) all the shipped core Magento class aliases are lowercase. When in doubt, follow the leader.

Side Note: A similar principle leads me to eschew inter camel casing class names like

Me_MyModule

Instead, I use

Me_Mymodule

Magento itself doesn't follow this practice, but I've been bitten too many times by the class autoloader and the impossibility of creating consistent followable rules for inter-casing (Something vs. SomeThing, etc.)

As far as

<model>
    <me_mymodule>
        <class>Me_MyModule_Model</class>
    </me_mymodule>
</model>

vs.

<model>
    <mymodule>
        <class>Me_MyModule_Model</class>
    </mymodule>
</model>

I favor the former. Magento merges all the XML configuration files into a single configuration tree, which means if you use the same node as another extension developer, you create potential problems down the line. Magento Inc. can get away with single word group names (Mage::getModel('groupname/class-name'),Mage::getModel('catalog/product'), etc.) because they own the platform, and stepping on a Magento module group name is clearly wrong, whereas two extension providers are more on a level playing field, so it's not clear who should have "the rights" to a unique name.

Alana Storm
  • 44,345
  • 35
  • 168
  • 353