我正在尝试在Magento中使用ajax加载一个块。为此,控制器需要创建一个块,并将一个数据数组传递给该块的模板。这部分很简单,我已经让它工作了。
但是,被调用的模板还会尝试调用一个块和setData
$this->getChild('customerfriends.event.edit')->setData(
    'event', $event);
echo $this->getChild('customerfriends.event.edit')->toHtml(); $this似乎不是导致致命错误的对象。
有什么东西我需要放到我的课上吗?
class Namespace_Mymodule_Block_Event_Listsection extends Mage_Core_Block_Template
{
}发布于 2013-09-13 01:21:05
$this似乎不是导致致命错误的对象。
如果模板正在被调用,那么$this必须是一个类实例;引用Mage_Core_Block_Template::fetchView(),并从那里回溯。问题是您的代码假设存在一个$this子块,其别名为为customerfriends.event.edit,并立即执行对象操作($returnedObject->setData())。
问题的解决方案取决于确定如何将别名为的customerfriends.event.edit块指定为任何块实例$this的子级。在Magento中,这可以通过布局XML以以下三种方式之一实现:
其一:
<reference name="theParentBlock">
    <block name="customerfriends.event.edit" ... />
</reference>二:
<reference name="theParentBlock">
    <action method="insert"><block>customerfriends.event.edit</block></action>
</reference>三:
<block name="customerfriends.event.edit" ... parent="theParentBlock" />这也可以直接在PHP中完成,通常在loadLayout()或类似的调用之后在控制器中完成。
另外,要注意父块(在您的例子中是$this)通过别名“知道”它们的子块。如果未指定别名,则使用layout中的块名称作为别名。您可以将布局XML中的别名识别为as属性或insert操作的第四个参数:
<reference name="theParentBlock">
    <block name="customerfriends.event.edit" ... as="theAlias" />
</reference>和
<reference name="theParentBlock">
    <action method="insert">
        <block>customerfriends.event.edit</block>
        <sibling />
        <after />
        <alias>theAlias</alias>
    </action>
</reference>您可以通过执行以下操作来查看父项的子项列表:
Zend_Debug::dump(array_keys($this->getChild()));https://stackoverflow.com/questions/18768543
复制相似问题