1

Why we are using Capitalization (first letter in caps).

In case of Any folder name like block, model or any controller file name. But in case of controller folder it's start with small latter.

Also some time in xml file we are using small letter but some time start with Caps. Like when we write any event name all are in small letter or when we call source in system.xml then we use class name in small letter. But when we declare the module name in xml then it is start with caps.

Can you please brief me the conditional logic behind it where we have to use small letter and where we have to start with Caps ?

2 Answers 2

4

Have a look at this response regarding the controllers directory and checkout out this topic to get some background on the class name capitalization conventions, these two topics should answer your questions.

1

See following official magento series then you will be able to understand magento1 flow

1. https://www.youtube.com/watch?v=KtBaozxkFgI
2. https://www.youtube.com/watch?v=lmQ1IfohDWk
3. https://www.youtube.com/watch?v=mh9VxfUZTNk

When you call something like this

Mage::getModel('sales/order');

What's happened?

Go to app/Mage.php

/**
 * Retrieve model object
 *
 * @link    Mage_Core_Model_Config::getModelInstance
 * @param   string $modelClass
 * @param   array|object $arguments
 * @return  Mage_Core_Model_Abstract|false
 */
public static function getModel($modelClass = '', $arguments = array())
{
    return self::getConfig()->getModelInstance($modelClass, $arguments);
}

Now go to app/code/core/Mage/Core/Model/Config.php

/**
 * Retrieve class name by class group
 *
 * @param   string $groupType currently supported model, block, helper
 * @param   string $classId slash separated class identifier, ex. group/class
 * @param   string $groupRootNode optional config path for group config
 * @return  string
 */
public function getGroupedClassName($groupType, $classId, $groupRootNode=null)
{

    ....
    .....
    // Second - if entity is not rewritten then use class prefix to form class name
    if (empty($className)) {
        if (!empty($config)) {
            $className = $config->getClassName();
        }
        if (empty($className)) {
            $className = 'mage_'.$group.'_'.$groupType;
        }
        if (!empty($class)) {
            $className .= '_'.$class;
        }
        $className = uc_words($className);
    }

    $this->_classNameCache[$groupRootNode][$group][$class] = $className;
    return $className;
}

Look $className = uc_words($className); here they convert capitalize. Magento 1 use capitalize for model, helper, block. I think video tutorial will help you most.

For Magento2, see psr documentation from here

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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