PHP Autoload
function __autoload($class_name){
require('lib/'.strToLower($class_name).'.class.php');
}
Magento Autoload
You cansplit all Magento classes into four parts that we’ll call Namespace, ModuleName, Class Type, and Name.
Namespace_ModuleName_ClassType_Name
Directory Structure
Varien’s current recommendation is that all non-core modules be stored in the local folder.
Namespace/ModuleName/ClassType/Name.php
Abstracting Away Class Instantiation
Magento Config Files
For example:
Mage::getModel('dataflow/batch_export');
ð
Mage_Dataflow_Model_Batch_Export
With your Own Modules
High Concept
The Cart Model has a method named removeItem.
<!-- .... -->
<global>
<models>
<!-- standard model section -->
<roimagic>
<class>Companyname_RoiMagic_Model</class>
</roimagic>
<!-- new checkout section -->
<checkout>
<rewrite>
<cart>Companyname_RoiMagic_Model_Cart</cart>
</rewrite>
</checkout>
</models>
</global>
<!-- .... -->
The<rewrite> node lets Magento know we want to override something in thedefault customer module. Remember, Magento merges all the config filestogether, so it’s seeing something more like
<checkout>
<class>Mage_Checkout_Model</class>
<resourceModel>checkout_mysql4</resourceModel>
<rewrite>
<cart>Companyname_RoiMagic_Model_Cart</cart>
</rewrite>
</checkout>
The presence of the <rewrite> node lets Magento know it shouldn’t assume the class you want isMage_Checkout_Model_Cart
. that’sCompanyname_RoiMagic_Model_Cart
Wrap-up