问题描述
此代码不起作用使我有些恼火.有什么建议吗?
I am getting a little irritated by this code not working. Any advice?
找不到新创建的massAction,而是404?
The newly created massAction is not found, but rather a 404?
config.xml:
<?xml version="1.0"?>
<config>
<modules>
<SNH_ShipMailInvoice>
<version>0.1.0</version>
</SNH_ShipMailInvoice>
</modules>
<global>
<events>
<!-- Event to attach observer to -->
<core_block_abstract_to_html_before>
<observers>
<SNH_ShipMailInvoice>
<type>singleton</type>
<!-- Observer location (e.g. SW/GridExample/Model) -->
<class>SNH_ShipMailInvoice_Model_Observer</class>
<!-- Function to call -->
<method>addMassAction</method>
</SNH_ShipMailInvoice>
</observers>
</core_block_abstract_to_html_before>
</events>
</global>
<admin>
<routers>
<adminhtml>
<args>
<modules>
<!-- Override Adminhtml module here. -->
<SNH_ShipMailInvoice before="Mage_Adminhtml">SNH_ShipMailInvoice</SNH_ShipMailInvoice>
</modules>
</args>
</adminhtml>
</routers>
</admin>
</config>
Observer.php
运行正常,并显示选项(如下):
Observer.php
is working fine and shows the option (below):
<?php
class SNH_ShipMailInvoice_Model_Observer
{
public function addMassAction($observer)
{
$block = $observer->getEvent()->getBlock();
// Check if this block is a MassAction block
if ($block instanceof Mage_Adminhtml_Block_Widget_Grid_Massaction) {
// Check if we're dealing with the Orders grid
if ($block->getParentBlock() instanceof Mage_Adminhtml_Block_Sales_Order_Grid) {
// The first parameter has to be unique, or you'll overwrite the old action.
$block->addItem('ship_mail_invoice', array(
'label' => Mage::helper('sales')->__('Ship, Mail and Invoice'),
'url' => $block->getUrl('*/*/shipmailinvoice'),
)
);
}
}
}
现在,当我选择新创建的选项时,我会收到404 not found错误.该URL类似于admin/sales_order/shipmailinvoice/key/
.
Now when I select the newly created option I receive a 404 not found error. The URL is something like admin/sales_order/shipmailinvoice/key/
.
OrderController.php
文件位于SNH/ShipMailInvoice/controllers/Adminhtml/Sales/OrderController.php
中:
require_once('Mage/Adminhtml/controllers/Sales/OrderController.php');
class SNH_ShipMailInvoice_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
public function shipmailinvoiceAction()
{
// This should be called when the url has the pattern '*/*/attack' (as it does
// when displaying my custom tab) however clicking this tab gives a 404.
die('<h1>attackAction()</h1>');
}
}
推荐答案
文件位置和XML命名非常具体
File location and XML naming is very specific
在config.xml中:
in config.xml:
<admin>
<routers>
<adminhtml>
<args>
<modules>
<!-- Override Adminhtml module here. -->
<SNH_ShipMailInvoice_Adminhtml before="Mage_Adminhtml">SNH_ShipMailInvoice_Adminhtml</SNH_ShipMailInvoice_Adminhtml>
</modules>
</args>
</adminhtml>
</routers>
</admin>
并将OrderController放在此处:
And OrderController should be placed here:
从此开始
class SNH_ShipMailInvoice_Adminhtml_Sales_OrderController extends Mage_Adminhtml_Sales_OrderController
{
public function shipmailinvoiceAction()
这篇关于Magento无法通过OrderController创建MassAction.这是怎么回事?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!