質問

Hello friend i need to over ride magento core controller

i want to override a Mage\ImportExport\controllers\Adminhtml\ExportController.php

In my community\compnyname\modulename\controllers\Adminhtml

this is my config.xml in \compnyname\modulename\etc

<?xml version="1.0" encoding="utf-8"?>
<config>
    <modules>
        <company_module>
            <version>1.0</version>
        </company_module>
    </modules>
    <global>
        <rewrite>
            <company_module>
                <from><![CDATA[#^/controller/adminhtml/#]]></from>
                <to>/controller/adminhtml/</to>
            </company_module>
        </rewrite>
    </global>
</config>

this is my controller code in \compnyname\modulename\controllers\Adminhtml\ExportController.php

<?php
require_once('/Mage/ImportExport/controllers/Adminhtml/ExportController.php');
class company_module_ImportExport_Controller_Adminhtml_ExportController extends Mage_ImportExport_Adminhtml_ExportController
{
    function indexAction()
    {
        echo "i am called";die;
    }
}
?>

Please help me in override a controller

Where is problem in my code?

役に立ちましたか?

解決

A rewrite like that is deprecated since Magento 1.3 (2009). You can read more about it here.

What you would want to do instead is like the following:

<admin>
    <routers>
        <adminhtml>
            <args>
                <modules>
                    <companyname_exportproduct before="Mage_ImportExport_Adminhtml">Companyname_ExportProduct_Adminhtml</companyname_exportproduct>
                </modules>
            </args>
        </adminhtml>
    </routers>
</admin>

Your classname and require looks a bit off as well. And it's good practice to not end php class files with a php end tag since it could accidentally include a whitespace that would mess up sent headers order.

So having said that I'd change your class file to:

<?php
require_once('Mage/ImportExport/controllers/Adminhtml/ExportController.php');
class Companyname_ExportProduct_Adminhtml_ExportController extends Mage_ImportExport_Adminhtml_ExportController
{
    function indexAction()
    {
        echo "i am called";die;
    }
}

And just in case you have forgot I'm including the file you would have to have in app/etc/modules to make your module active:

<config>
    <modules>
        <Companyname_ExportProduct>
            <active>true</active>
            <codePool>community</codePool>
        </Companyname_ExportProduct>
    </modules>
</config>

他のヒント

Check the below links.
Link 1
Link 2

I hope this may help you.

This is a little notification on the include path of the controller.

This include path can cause errors if the Magento Compiler mode is turned on.

require_once 'Mage/ImportExport/controllers/Adminhtml/ExportController.php';

Instead of that it is good to use

require_once Mage::getModuleDir('controllers', 'Mage_ImportExport').DS.'Adminhtml_ExportController.php';

It will be safer. Hope this helps..

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top