Class Naming Conventions and Their Relationship with the Autoloader (Magento Certified Developer Exam)

We suppose you continue following our Magento certification-dedicated posts in our blog. This time we will tell you about class naming conventions and their relationship with the autoloader.

Magento was developed based on the Zend Framework, so the rules of class naming in Magento were taken from the Zend Framework (read more here).

Magento standardizes class names depending on their location in the file system. Such standardization enables automatic class loading (autoloader) instead of using require_once and include_once functions. Rather than the directory separator (‘/’ – invalid character for class names), developers use the underscore character (‘_’).

For example, the Mage_Catalog_Model_Product class is located in the /app/code/core/Mage/Catalog/Model/Product.php category. Magento autoloader replaces all underscore characters (‘_’) with the category separator (‘/’) and looks for the file in one of the categories (/app/code/local can be disabled in the app/etc/local.xml in the disable_local_modules tag).

 – /app/code/core

– /app/code/community

– /app/code/local

– /lib/

File search categories in Magento are defined in app/Mage.php.

The Varien_Autoload class is used for automatic upload:

 Creating objects in Magento

Magento provides a special method to create models, helpers and blocks, using the Mage global class with a shortened class name. For example, to get the Mage_Catalog_Model_Product model in Magento the Mage :: getModel (‘catalog / product’) method is commonly used.

catalog – shortening for  Mage_Catalog_Model
product – determines which class will be used

Correlation of the class name with a shortened name takes place in the module configuration (/etc/config.xml).

Read our previous posts.

Magento Codepools

Magento Module Structure

The Main Magento Design Areas and More…



2 comments

  1. Pingback: Get Ready for Magento Certified Developer Exam. Describing Methods for Resolving Module Conflicts | BelVG Blog
  2. Hi guys,

    the code isnt showing in your posts. Is there a bug with the Crayon WP Plugin? Can you check this please?

    By the way, awesome articles. ) Thanks for sharing such detailed informations! You are great.

    Cheers, Max

Post a new comment

top
BelVG Newsletter
Subscribe to our mailing list and get interesting stuff and updates to your email inbox.
Email *