6

我创建了一个自定义管理模块,但我无法在其中放入内容,它总是空白我正在尝试使用简单的代码进行测试,但似乎没有任何效果

public function indexAction()
{
    $this->loadLayout();

    $this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml')->toHtml());
    $this->renderLayout();
}

.phtml 中的

echo 'hello world';

但不打印任何内容,如果在 phtml 中出错,系统崩溃,这意味着它正在获取文件,但是,我缺少什么,请帮助

4

1 回答 1

10

管理控制器上的$this->_addContent方法需要传递一个块对象。

protected function _addContent(Mage_Core_Block_Abstract $block)
{
    $this->getLayout()->getBlock('content')->append($block);
    return $this;
}

你传入

$this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml')->toHtml()

这是一个字符串。你渲染得太早了。如果你检查你的日志,你应该会看到一个警告/错误/告诉你参数_addContent是意外类型的东西。

尝试不调用 toHtml 方法

$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('uhmaadmin/contactos.list.phtml'));
于 2010-08-18T16:27:32.553 回答