美文网首页
magento二次开发 - 如何复写核心模块中的controll

magento二次开发 - 如何复写核心模块中的controll

作者: jimxu | 来源:发表于2017-10-23 11:16 被阅读82次

我们想要对core中的一些模块的controller里的一些方法进行修改,自然不能直接在controller中修改,要通过复写(rewrite)的方法在local中操作
复写的原理是同名的模块会按优先级覆盖,优先级为:local > community > core

以复写Customer/AccountController.php为例

先在controllers目录下新建Customer文件夹,建立Nano_App_AccountController类文件,继承原有的Mage_Customer_AccountController

<?php
require_once Mage::getModuleDir('controllers', "Mage_Customer").DS."AccountController.php";
class Nano_App_AccountController extends Mage_Customer_AccountController
{
    /**
     * Login post action
     */
    public function loginPostAction()
    {
        echo 'login post has been rewritten';
    }
} 

再修改app模块的配置文件config.xml,在global标签下对AccountContoller进行复写

<global>
    <!-......-->
     <rewrite>
         <Nano_App>
              <from><![CDATA[#^/customer/account/loginPost/#]]></from>
              <to>/app/customer/account/loginPost/</to>
          </Nano_App>
      </rewrite>
      <!-......-->
</global>

相关文章

网友评论

      本文标题:magento二次开发 - 如何复写核心模块中的controll

      本文链接:https://www.haomeiwen.com/subject/gywzdttx.html