Magento’s Class Instantiation Abstraction and Autoload

11 篇文章 0 订阅

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 is Mage_Checkout_Model_Cart. that’s Companyname_RoiMagic_Model_Cart
 

Wrap-up

 
 

 


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值