我正在尝试解决我的块输出为空字符串的问题。
我将其追溯到可以在模板文件中看到PHP语句被评估的程度,但是在toHtml()
类的Mage_Core_Block_Abstract
内,$html = $this->_toHtml();
将空字符串赋给{{1} }}
我进一步挖掘,发现在$html
内,fetchView()
为其分配空字符串,即使模板包含在此行上方,我也可以看到它使用调试器进行评估
从这里我对如何调试这一点毫无头绪,可能是我在模块中遗漏了一些错误(我是Magento的初学者)。
以下是该模块的相关代码:
应用/代码/本地/ AnattaDesign / AbandonedCarts的/ etc / config.xml中
$html = ob_get_clean();
应用/设计/ adminhtml /碱/默认/布局/ layout.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>
应用/代码/本地/ AnattaDesign / AbandonedCarts /控制器/ WidgetController.php
<?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 /砌块/ Widget.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();
}
}
我是由管理员控制器运行它并使<?php
class AnattaDesign_AbandonedCarts_Block_Widget extends Mage_Core_Block_Template {
}
开火。
答案 0 :(得分: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 );
}
}