magento 屏蔽某个模块的访问(以customer为例)

 最近做了项目,客户要求前端不允许看见customer模块的相关内容,在后台system->configuration->advance,关闭customer模块,但是地址栏输入`www.xample.com/customer/account`,页面跳转出现异常,为了避免这种情况,就要对url的访问进行限制,当访问该模块的相干内容时,跳转到404的错误页面。

1、新建一个模块Silk_Xcustomer:

 ---etc
   ---modules
     ---Silk_Xcustomer.xml

2、在code/local下:

Silk
 ---Xcustomer
  ---etc
  ---controllers  

3、config.xml文件中写入代码:

<?xml version='1.0'?>
<config>
<modules>
    <Silk_Xcustomer>
        <version>0.1.0</version>
    </Silk_Xcustomer>
</modules>
<frontend>/*重写前台controllers,如果是重写后台controllers,这里应该写为admin*/
    <routers>
        <xcustomer>
            <use>standard</use>
            <args>
                <module>Silk_Xcustomer</module>
                <frontName>xcustomer</frontName>
            </args>
        </xcustomer>
        <customer>/*被重写控制器所在的模块的NameSpace*/
          <!--<customer>-->/*这个是customer在Mage下面的命名NameSpace*/
            <!--<use>standard</use>-->
            <!--<args>-->
                <!--<module>Mage_Customer</module>-->
                <!--<frontName>customer</frontName>-->
            <!--</args>-->
         <!--</customer>-->
            <use>standard</use>
            <args>
                <modules>
                    <Silk_Xcustomer before="Mage_Xcustomer">Silk_Xcustomer</Silk_Xcustomer>/*重写customer下AccountController*/
                </modules>
            </args>
        </customer>
     </routers>
    </frontend>
</config>

4、在controllers下新建AccountController.php

<?php

include_once 'Mage/Customer/controllers/AccountController.php';/*重写控制器一定要有这句话,不然重写失败,但重写block、model、helper没有这句话,切记*/
class Silk_Xcustomer_AccountController extends Mage_Customer_AccountController
{
    /*加载no-route页面*/
    public function defaultNoRouteAction()
    {
        $this->getResponse()->setHeader('HTTP/1.1','404 Not Found');
        $this->getResponse()->setHeader('Status','404 File not found');

        $this->loadLayout();
        $this->renderLayout();
    }

    /*屏蔽customer登录相关页面,这里屏蔽这一个页面就可以了,其他相关页面需要用户的登录才能访问*/
    public function loginAction()
    {
        /*获取404页面的Id*/
        $pageId = Mage::getStoreConfig(Mage_Cms_Helper_Page::XML_PATH_NO_ROUTE_PAGE);
        if (!Mage::helper('cms/page')->renderPage($this, $pageId)) {
            $this->_forward('defaultNoRoute');
        }
    }

    /*屏蔽customer注册相关页面*/
    public function createAction()
    {
        $this->_forward('login');
    }

}

5、当在浏览器中输入www.xample.com/customer/account时,页面就会自动的跳转到404页面

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值