【问题标题】:Magento : Call to a core block inside my moduleMagento:调用我模块中的核心块
【发布时间】:2013-03-04 10:00:21
【问题描述】:


你好, 我正在编写一个 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()

【问题讨论】:

  • 来电是什么意思?您可以通过&lt;block type="core/template"... /&gt; 插入它
  • 是的。我想在 layout.xml 中的处理程序中插入核心块
  • 是的,就这么做。如果你已经完成了,如果它不起作用,请显示代码
  • 你能编辑你的问题吗? cmets 中的代码不可读

标签: php magento


【解决方案1】:

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

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

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

// load your order here..
Mage::register('sales_order', $order);

【讨论】:

  • 非常感谢。在寄存器中保存订单 ID 后,错误已修复。
  • 嗨,我在处理程序中添加了块。但是当我添加评论并提交时,它没有显示在 cmets 列表中。请帮忙?
【解决方案2】:

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

<!-- 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>

【讨论】:

  • 感谢您的解决方案。我已经试过了。但它没有用。请问有什么建议吗?
  • 嗨,我想在 adminhtml/default/default/layout/sales.xml 中插入以下块
  • 在你的控制器动作中你写过 $this->loadLayout()->renderLaout();...?
  • 有时直接reference"content" 不会执行所有孩子的想法。您可以尝试将它们封装在包装器中。这不是推荐的解决方案,但您可以尝试。 &lt;reference name="content"&gt;&lt;block type="orderadmin/adminhtml_search" name="search_order"&gt;&lt;block type="adminhtml/sales_order_view_history" name="order_history" template="sales/order/view/history.phtml"/&gt;&lt;/block&gt; 和你的 phtml 尝试使用 echo $this-&gt;getChildHtml('order_history')
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-08
  • 1970-01-01
  • 1970-01-01
  • 2015-09-22
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多