最近做了项目,客户要求前端不允许看见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页面 (责任编辑:最模板) |