Uza*_*med 4 magento magento-1.5
我试图在本地池中使用我的自定义控制器重载/重写核心Onepagecontroller,但它无法正常工作.我正在使用Magento 1.5.1
这是我的文件结构和代码:
控制器文件:\ app\code\local\Odc\Mycheckout\controllers\OnepageController.php
require_once 'Mage/Checkout/controllers/OnepageController.php';
class Odc_Mycheckout_OnepageController extends Mage_Checkout_OnepageController
{
public function indexAction()
{
echo "This controller has been overridden.";
}
}
Run Code Online (Sandbox Code Playgroud)
config.xml文件:\ app\code\local\Odc\Mycheckout\etc\config.xml
<?xml version="1.0"?>
<config>
<modules>
<Odc_Mycheckout>
<version>0.0.1</version>
</Odc_Mycheckout>
</modules>
<global>
<controllers>
<Mage_Checkout>
<rewrite>
<onepage>Odc_Mycheckout_Onepage</onepage>
</rewrite>
</Mage_Checkout>
</controllers>
</global>
<frontend>
<routers>
<mycheckout>
<args>
<modules>
<Odc_Mycheckout before="Mage_Checkout">Odc_Mycheckout</Odc_Mycheckout>
</modules>
</args>
</mycheckout>
</routers>
</frontend>
</config>
Run Code Online (Sandbox Code Playgroud)
Odc_Mycheckout.xml文件:\ app\etc\module\Odc_Mycheckout.xml
<?xml version="1.0"?>
<config>
<modules>
<Odc_Mycheckout>
<active>true</active>
<codepool>local</codepool>
</Odc_Mycheckout>
</modules>
</config>
Run Code Online (Sandbox Code Playgroud)
CamelCase再次罢工.
Odc_Mycheckout.xml文件:\ app\etc\module\Odc_Mycheckout.xml
<?xml version="1.0"?>
<config>
<modules>
<Odc_Mycheckout>
<active>true</active>
<codePool>local</codePool> <!-- Capital P in pool -->
Run Code Online (Sandbox Code Playgroud)
另外,在您的模块配置文件中:
<frontend>
<routers>
<checkout> <!-- must match the router config you are trying to override -->
<args>
<modules>
<Odc_Mycheckout before="Mage_Checkout">Odc_Mycheckout</Odc_Mycheckout>
</modules>
</args>
</checkout>
</routers>
</frontend>
Run Code Online (Sandbox Code Playgroud)
编辑:
要在重写的控制器不工作时进行故障排除,可以帮助回到基础.一种方法是使用相同的方法Mage_Core_Controller_Varien_Router_Standard.在脚本test.php中:
<?php
ini_set('display_errors',1);
include 'app/Mage.php';
Mage::setIsDeveloperMode(true);
Mage::app();
$module = 'Odc_Mycheckout';
$controller = 'Onepage';
$router = new Mage_Core_Controller_Varien_Router_Standard;
$filename = $router->getControllerFileName($module,$controller);
$classname = $router->getControllerClassName($module,$controller);
include $filename;
$controller = Mage::getControllerInstance(
$classname,
Mage::app()->getRequest(),
Mage::app()->getResponse()
);
var_dump($controller); //should be a class
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1906 次 |
| 最近记录: |