如何重写一个Magento控制器方法
展开全部
1.创建模块文件
app/code/local/Wangdz/Checkout/etc/config.xml
app/code/local/Wangdz/Checkout/controllers/CartController.php
app/etc/modules/Wangdz_All.xml
2. 编辑 /etc/config.xml文件
创建 app/code/local/Wangdz/Checkout/etc/config.xml文件并添加以下内容:
<?xml version="1.0"?>
<config>
<modules>
<Wangdz_Checkout>
<version>0.1.0</version>
</Wangdz_Checkout>
</modules>
<frontend>
<routers>
<wangdz_checkout>
<use>standard</use>
<args>
<module>Wangdz_Checkout</module>
<frontName>wangdz_checkout</frontName>
</args>
</wangdz_checkout>
</routers>
</frontend>
<global>
<blocks>
<wangdz_checkout>
<class>Wangdz_Checkout_Block</class>
</wangdz_checkout>
</blocks>
<rewrite>
<wangdz_checkout_cart>
<from><![CDATA[#^/checkout/cart/#]]></from>
<to>wangdz_checkout/cart/</to>
</wangdz_checkout_cart>
</rewrite>
</global>
</config>
3. 编辑 ”controllers/CartController.php”文件
app/code/local/Wangdz/Checkout/controllers/CartController.php 添加以下内容:
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Wangdz_Checkout_CartController extends Mage_Checkout_CartController {
public function indexAction() {
echo "hello world!";
}
}
?>
4. 编辑”app/etc/modules/Wangdz_All.xml”文件
<Wangdz_Checkout>
<active>true</active>
<codePool>local</codePool>
</Wangdz_Checkout>
5. 将浏览器指向 /checkout/cart/
你会看到页面打印出:”hello world!”
app/code/local/Wangdz/Checkout/etc/config.xml
app/code/local/Wangdz/Checkout/controllers/CartController.php
app/etc/modules/Wangdz_All.xml
2. 编辑 /etc/config.xml文件
创建 app/code/local/Wangdz/Checkout/etc/config.xml文件并添加以下内容:
<?xml version="1.0"?>
<config>
<modules>
<Wangdz_Checkout>
<version>0.1.0</version>
</Wangdz_Checkout>
</modules>
<frontend>
<routers>
<wangdz_checkout>
<use>standard</use>
<args>
<module>Wangdz_Checkout</module>
<frontName>wangdz_checkout</frontName>
</args>
</wangdz_checkout>
</routers>
</frontend>
<global>
<blocks>
<wangdz_checkout>
<class>Wangdz_Checkout_Block</class>
</wangdz_checkout>
</blocks>
<rewrite>
<wangdz_checkout_cart>
<from><![CDATA[#^/checkout/cart/#]]></from>
<to>wangdz_checkout/cart/</to>
</wangdz_checkout_cart>
</rewrite>
</global>
</config>
3. 编辑 ”controllers/CartController.php”文件
app/code/local/Wangdz/Checkout/controllers/CartController.php 添加以下内容:
<?php
require_once 'Mage/Checkout/controllers/CartController.php';
class Wangdz_Checkout_CartController extends Mage_Checkout_CartController {
public function indexAction() {
echo "hello world!";
}
}
?>
4. 编辑”app/etc/modules/Wangdz_All.xml”文件
<Wangdz_Checkout>
<active>true</active>
<codePool>local</codePool>
</Wangdz_Checkout>
5. 将浏览器指向 /checkout/cart/
你会看到页面打印出:”hello world!”
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询