1

我正在尝试解决我的块输出为空字符串的问题。

我将其追踪到可以看到在模板文件中评估 PHP 语句的点,但在toHtml()class内部Mage_Core_Block_Abstract$html = $this->_toHtml();将空字符串分配给$html.

fetchView()我进一步挖掘它,发现 inside$html = ob_get_clean();为其分配了空字符串,即使模板包含在这一行之上,我也可以看到它使用调试器进行评估。

从这里我对如何调试它一无所知,可能是我的模块中遗漏了一些错误(我是 Magento 的初学者)。

这是模块中的相关代码:

应用程序/代码/本地/AnattaDesign/AbandonedCarts/etc/config.xml

<config>
    <global>
        <blocks>
            <anattadesign_abandonedcarts>
                <class>AnattaDesign_AbandonedCarts_Block</class>
            </anattadesign_abandonedcarts>
        </blocks>
    </global>
    <adminhtml>
    <layout>
        <updates>
            <anattadesign_abandonedcarts>
                <file>layout.xml</file>
            </anattadesign_abandonedcarts>
        </updates>
    </layout>
</adminhtml>

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

<?xml version="1.0" encoding="utf-8"?>
<layout>
    <adminhtml_dashboard_index>
        <reference name="head">
            <action method="addCss">
                <stylesheet>anattadesign/abandonedcarts/css/style.css</stylesheet>
            </action>
            <action method="addJs">
                <script>anattadesign/abandonedcarts/zepto.js</script>
            </action>
            <action method="addJs">
                <script>anattadesign/abandonedcarts/adminhack.js</script>
            </action>
        </reference>
    </adminhtml_dashboard_index>
</layout>

应用程序/代码/本地/AnattaDesign/AbandonedCarts/controllers/WidgetController.php

<?php

class AnattaDesign_AbandonedCarts_WidgetController extends Mage_Adminhtml_Controller_Action {

    public function indexAction() {
        echo "index action of widget controller";
        die();
    }

    public function renderAction() {
        $html = $this->getLayout()->createBlock( 'anattadesign_abandonedcarts/widget', 'root' )->setTemplate( 'anattadesign/abandonedcarts/widget.phtml' )->toHtml();
        $this->getResponse()->setBody( $html );
        die();
    }
}

应用程序/代码/本地/AnattaDesign/AbandonedCarts/Block/Widget.php

<?php

class AnattaDesign_AbandonedCarts_Block_Widget extends Mage_Core_Block_Template {

}

我正在由管理员控制器运行它并renderAction()生火。

4

1 回答 1

5

移除方法 renderAction() 中的 die()

class AnattaDesign_AbandonedCarts_WidgetController extends Mage_Adminhtml_Controller_Action {

    ....

    public function renderAction() {
        $html = $this->getLayout()->createBlock( 'anattadesign_abandonedcarts/widget')
                ->setTemplate( 'coming.phtml' )
                ->toHtml();
        $this->getResponse()->setBody( $html );
    }
}
于 2012-11-03T20:30:25.537 回答