Magento布局块方法不触发

时间:2018-09-29 12:27:37

标签: php magento magento-1.9 magento-layout-xml

我正在尝试通过添加模板文件在订单视图中包括一个新块,我想从其块中调用方法“ getText()”,但该方法不起作用,感谢帮助。

我已经创建了布局文件

/app/design/adminhtml/default/default/template/sales/order/cardmessage.phtml

我已经使用方法getText()创建了该块;

/app/code/core/Mage/Adminhtml/Block/Sales/Order/View/Cardmessage.php

内容(Cardmessage.php)

class Mage_Adminhtml_Block_Sales_Order_View_Cardmessage extends Mage_Adminhtml_Block_Sales_Items_Abstract
{
    /**
     * Retrieve required options from parent
     */
    protected function _beforeToHtml()
    {
        if (!$this->getParentBlock()) {
            Mage::throwException(Mage::helper('adminhtml')->__('Invalid parent block for this block'));
        }
        $this->setOrder($this->getParentBlock()->getOrder());
        parent::_beforeToHtml();
    }

    /**
     * Retrieve order items collection
     *
     * @return unknown
     */
    public function getItemsCollection()
    {
        return $this->getOrder()->getItemsCollection();
    }

    public function getText()
    {
        return "test text";
    }

}

并将模板注册到sales.xml

/app/design/adminhtml/default/default/layout/sales.xml

内容(sales.xml)。

<adminhtml_sales_order_view>
    <reference name="head">
        <action method="addJs"><file>mage/adminhtml/giftmessage.js</file></action>
        <action method="addJs"><file>mage/adminhtml/giftoptions/tooltip.js</file></action>
    </reference>
    <reference name="content">
        <block type="adminhtml/sales_order_view" name="sales_order_edit"></block>
    </reference>
    <reference name="left">
        <block type="adminhtml/sales_order_view_tabs" name="sales_order_tabs">
            <block type="adminhtml/sales_order_view_tab_info" name="order_tab_info" template="sales/order/view/tab/info.phtml">
                <block type="adminhtml/sales_order_view_messages" name="order_messages"></block>
                <block type="adminhtml/sales_order_view_info" name="order_info" template="sales/order/view/info.phtml"></block>
                <block type="adminhtml/sales_order_view_cardmessage" name="order_cardmessage" template="sales/order/view/cardmessage.phtml"></block> <-- added entry

但是我插入cardmessage.phtml中的任何文本都显示出我无法从块中调用方法。

0 个答案:

没有答案