本文介绍了Magento目录ProductController重写的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试使用模块覆盖magento Mage \ Catalog \ controllers \ ProductController.php.在我的模块中,我尝试这样做:

I try to override the magento Mage\Catalog\controllers\ProductController.php with a module. In my module i try this:

\ etc \ config.xml

\etc\config.xml

<global>
    <rewrite>        
        <aion_fbpage_catalog_productcontroller>
            <from><![CDATA[#^catalog/product/#]]></from> <!-- Mage_Catalog_ProductController  -->
            <to>fbpage/catalog_product/</to> <!-- Aion_FbPage_Catalog_ProductController  -->
        </aion_fbpage_catalog_productcontroller>
    </rewrite>
</global>
<frontend>
    <routers>
        <fbpage>
            <use>standard</use>
            <args>
                <module>Aion_FbPage</module>
                <frontName>fbPage</frontName>
            </args>
        </fbpage>
    </routers>
</frontend>

\ controllers \ Catalog \ ProductController.php

\controllers\Catalog\ProductController.php

<?php
require_once "Mage/Catalog/controllers/ProductController.php";

class Aion_FbPage_Catalog_ProductController extends Mage_Catalog_ProductController
{
    // My override stuff
}

当我尝试使用我的产品时,要看重写是做什么的,我会收到此错误:

And when i try to reach my product, to see what the rewrite does, i get this error:

如果我在课堂上什么也不做,我会收到相同的错误消息

I get the same error message, if i do nothing in my class

推荐答案

您可以像下面这样使用

编辑您Package/Module/etc/config.xml

<?xml version="1.0"?>
<config>
... Your Other config here ....
   <frontend> 
        <routers> 
          <catalog> 
             <args> 
             <modules> 
                <Package_Catalog before="Mage_Catalog">Package_Catalog</Package_Catalog>
             </modules> 
             </args> 
         </catalog> 
       </routers> 
   </frontend> 
</config>

现在您的控制器已经准备好了.

Now your controller already ready.

include(Mage::getBaseDir()."/app/code/core/Mage/Catalog/controllers/ProductController.php");
class Package_Catalog_ProductController extends Mage_Catalog_ProductController
{
      public function viewAction(){
             echo __METHOD__;
      }
}
?>

这篇关于Magento目录ProductController重写的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-20 17:12