magento复写core中的model

与复写controller比较类似的功能,在config.xml的配置上有一些差异

以复写Captcha模块下的Model下的Observer.php为例:

先在Model文件夹下新建Nano_App_Model_Observer类文件,继承原有的类Mage_Captcha_Model_Observer

app/code/local/Nano/App/Model/Observer.php
1
2
3
4
5
6
7
<?php
/**
* Rewrite Captcha Observer because error message should be given when captcha is not correct
*/
class Nano_App_Model_Observer extends Mage_Captcha_Model_Observer
{
}

再修改app模块的配置文件config.xml,使得复写生效

app/code/local/Nano/App/etc/config.xml
1
2
3
4
5
6
7
8
9
10
<models>
<nano_app>
<class>Nano_App_Model</class>
</nano_app>
<captcha>
<rewrite>
<observer>Nano_App_Model_Observer</observer>
</rewrite>
</captcha>
</models>

// Add comment count