如何调用自定义模块的管理控制器

时间:2014-08-07 05:30:35

标签: php magento plugins module controller

如何使用以下代码调用自定义模块的管理控制器。我曾尝试在Google上搜索但无法找到任何内容

以下是Mynamespace / TypeChanger / Block / Adminhtml / Catalog / Product / Grid.php的代码

class Mynamespace_TypeChanger_Block_Adminhtml_Catalog_Product_Grid extends Mage_Adminhtml_Block_Catalog_Product_Grid
{
        protected function _prepareMassaction()
    {
        parent::_prepareMassaction();

        // Append new mass action option
        $this->getMassactionBlock()->addItem(
                'typechanger',
                array('label' => $this->__('Change Type'),
                        'url'   => $this->getUrl('abc'),
        //this should be the url where there will be mass operation

            'additional' => array(
                        'visibility' => array(
                                'name' => 'type',
                                'type' => 'select',
                                'class' => 'required-entry',
                                'label' => Mage::helper('catalog')->__('Type'),
                                'values' => array('simple' => 'simple','grouped' => 'grouped' , 'configurable' => 'configurable' ,'virtual'=> 'virtual', 'bundle'=> 'bundle', 'downloadable'=>'downloadable')
                            )

            )

            )
            );
    }
}

这是config.xml的代码

 <?xml version="1.0"?>
    <config>
        <modules>
            <Mynamespace_TypeChanger>
                <version>1.0</version>
            </Mynamespace_TypeChanger>
        </modules>

        <admin>
            <routers>
                <typechanger>
                    <use>admin</use>
                    <args>
                        <module>Mynamespace_TypeChanger</module>
                        <frontName>abc</frontName>
                    </args>
                </typechanger>
            </routers>

        </admin>

       <global>
            <blocks>
                <adminhtml>
                    <rewrite>
                        <catalog_product_grid>Mynamespace_TypeChanger_Block_Adminhtml_Catalog_Product_Grid</catalog_product_grid>
                    </rewrite>
                </adminhtml>
            </blocks>

        <helpers>
                <typechanger>
                    <class>Mynamespace_TypeChanger_Helper</class>
                </typechanger>
        </helpers>

        </global>

    </config>

1 个答案:

答案 0 :(得分:0)

您可以在Grid.php中添加url标记,如下所示

 $this->getMassactionBlock()->addItem(
                'typechanger',
                array('label' => $this->__('Change Type'),
                      'url'  => $this->getUrl('*/*/massChangeType', array('_current'=>true)),
        //this should be the url where there will be mass operation

            'additional' => array(
                        'visibility' => array(
                                'name' => 'type',
                                'type' => 'select',
                                'class' => 'required-entry',
                                'label' => Mage::helper('catalog')->__('Type'),
                                'values' => array('simple' => 'simple','grouped' => 'grouped' , 'configurable' => 'configurable' ,'virtual'=> 'virtual', 'bundle'=> 'bundle', 'downloadable'=>'downloadable')
                            )    
                 )    
               )
            );

你的控制器名称应该是

Mynamespace_TypeChanger_Adminhtml_Catalog_ProductController

anb路径应该像

\Mynamespace\TypeChanger\controllers\Adminhtml\Catalog\ProductController.php

您必须定义函数massChangeType或您的自定义名称。

并在config.xml

中使用以下重写管理员控制器
<admin>
        <routers>
            <adminhtml>
                <args>
                    <modules>
                        <Mynamespace_TypeChanger before="Mage_Adminhtml">Mynamespace_TypeChanger_Adminhtml</Mynamespace_TypeChanger>
                    </modules>
                </args>
            </adminhtml>
        </routers>
    </admin>