Class Naming Conventions and Their Relationship with the Autoloader

Apr 10, 2012497

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 Certification

Magento was developed based on the Zend Framework, so the rules of class naming in Magento were taken from the Zend Framework.

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:

Igor Dragun
Partner With Us Let's discuss how to grow your business. Get a Free Quote.
Talk to Igor

 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…

magento development services

Magento 2 Development

Take your online store to the next level with BelVG Magento 2 Development

Visit the page

Igor Dragun
Partner With Us Looking for a partner to grow your business? We are the right company to bring your webstore to success. Talk to Igor

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 *