Magento Local Module 会覆盖 Community Module

当magento的一个页面不存在时  会显示一个404页面,是在
System  => Configure => Web => Default pages => 
Default No-route URL : cms/index/noRoute
 
CMS No Route Page : 404 page


1) 在 app/code/comunity下创建module
Voyageone
                Cms
                      controllers
                                      IndexController.php
                etc
                       config.xml




IndexController.php
<?php


require_once Mage::getModuleDir('controllers', 'Mage_Cms').DS.'IndexController.php';


class Voyageone_Cms_IndexController extends Mage_Cms_IndexController
{
    /**
     * Render CMS 404 Not found page
     *
     * @param string $coreRoute
     */
    public function noRouteAction($coreRoute = null)
    {
        mage :: log(Mage::helper('core/url')->getHomeUrl().' first');


Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::helper('core/url')->getHomeUrl())
->sendResponse();


    }
}


config.xml
<?xml version="1.0"?>
<config>
    <modules>
<Voyageone_Cms>
   <version>0.1</version>
</Voyageone_Cms>
    </modules>
    <frontend>
        <routers>
            <cms>
                <args>
                    <modules>
                        <Voyageone_Cms before="Mage_Cms">Voyageone_Cms</Voyageone_Cms>
                    </modules>
                </args>
            </cms>
        </routers>
    </frontend>
</config>




app/etc/module 创建Voyageone_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Voyageone_Cms>
<active>true</active>
<codePool>community</codePool>
</Voyageone_Cms>
</modules>
</config>


当访问页面 http://localhost/magento/cms/index/noRoute时  会发现页面重定向到首页


2. 同样在 
app/code/local 下新建module
app/code/local/Devicom
                                 Cms
                                        controllers
                                                InderxController.php 
                                        etc
                                              config.xml
InderController.php
<?php


require_once Mage::getModuleDir('controllers', 'Mage_Cms').DS.'IndexController.php';


class Devicom_Cms_IndexController extends Mage_Cms_IndexController
{
    /**
     * Render CMS 404 Not found page
     *
     * @param string $coreRoute
     */
    public function noRouteAction($coreRoute = null)
    {
        mage :: log( Mage::getBaseUrl(). 'women/new-arrivals.html' ." second");
Mage::app()->getFrontController()->getResponse()
->setRedirect(Mage::getBaseUrl(). 'women/new-arrivals.html')
->sendResponse();


    }
}


config.xml:
<?xml version="1.0"?>
<config>
    <modules>
<Devicom_Cms>
   <version>0.1</version>
</Devicom_Cms>
    </modules>
    <frontend>
        <routers>
            <cms>
                <args>
                    <modules>
                        <Devicom_Cms before="Mage_Cms">Devicom_Cms</Devicom_Cms>
                    </modules>
                </args>
            </cms>
        </routers>
    </frontend>
</config>


app/etc/modules
                       Devicom_Cms.xml
<?xml version="1.0"?>
<config>
<modules>
<Devicom_Cms>
<active>true</active>
<codePool>local</codePool>
</Devicom_Cms>
</modules>
</config>


3. 当再次去访问页面http://localhost/magento/cms/index/noRoute时 显示的是 'women/new-arrivals.html‘
当查看system.log时 发现 first没有出现 而是second.
所以magento很聪明 知道哪个Module会被访问,而community下的CMS模块不在被执行。

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值