1


嗨,我正在编写一个 Magento 模块。为此,我想在我的模块处理程序中调用一个核心块。我不想修改或扩展核心块。我只想在我的布局处理程序中调用它。有什么建议么?

我要插入的块位于

adminhtml/sales/order/view/history.php

以下处理程序位于包含上述 Histrory.php 块的 sales.xml 中

 <adminhtml_sales_order_addcomment>
        <block type="adminhtml/sales_order_view_history" name="order_history" template="sales/order/view/history.phtml" output="toHtml"/>
    </adminhtml_sales_order_addcomment>

这是我的 layout.xml

       <orderadmin_adminhtml_orderadmin_search> 
        <update handle="orderadmin_orderadmin_search" />
         <reference name="content"> 
     <!-- I want to insert the following block --> 
        <block type="adminhtml/sales_order_view_history" name="order_history" template="sales/order/view/history.phtml" output="toHtml"/> 
</reference> 
</orderadmin_adminhtml_orderadmin_search>

但这会导致以下错误。

致命错误:在第 79 行的 \app\code\core\Mage\Adminhtml\Block\Sales\Order\View\History.php 中的非对象上调用成员函数 getId()

4

2 回答 2

1

你必须在你的代码中这样做:

<!-- this is my handler -->
<orderadmin_adminhtml_orderadmin_search>
        <update handle="orderadmin_orderadmin_search" />
        <reference name="content">
            <block type="orderadmin/adminhtml_search" name="search_order" />
            <!-- I want to call the core block here -->

从核心布局中提取您想要的块并按原样粘贴到此处,它将被渲染

        </reference>
    </orderadmin_adminhtml_orderadmin_search>
于 2013-03-04T10:43:06.593 回答
1

问题与 xml 布局无关,这实际上是正确的,并且可以按原样工作。

问题是因为这个块期望订单在注册表中,以使其能够获取历史记录。

在呈现历史记录块之前,您应该在控制器或模块块内的注册表中设置一个顺序(您希望用于查看历史记录的顺序)。

// load your order here..
Mage::register('sales_order', $order);
于 2013-03-04T11:59:15.017 回答