如何在magento自定义管理页面中显示内容?

时间:2011-06-23 17:47:55

标签: magento

如果我必须显示数据库中的一些数据,我如何在管理控制器中传递这些数据?假设我在控制器中定义了一个块

$block = $this->getLayout()->createBlock('core/text')->setText('<h1>Main Block</h1>');

我可以将任何类型的数据传递给setText()函数以显示我在管理页面中需要的数据还是有其他功能?我想在后端的自定义表中显示几个订单号。

我尝试过这样的事情:$block = $this->getLayout()->createBlock('core/text')->setText('<h1>Main Block</h1><div>'.$this->showAllRecordsAction().'</div>');

showAllRecordsAction()从自定义表中检索数据并显示它。当我尝试这个时,我看到页面顶部的数据而不是内容块中的数据。

如何在内容块中显示它?感谢。

1 个答案:

答案 0 :(得分:4)

我能够通过一个块显示内容。 在我的indexController中使用此代码:

$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('adminhelloworld/view'))
            ->renderLayout();

这是我在Block / View.php中的View.php

<?php
class Foostor_Adminhelloworld_Block_View extends Mage_Core_Block_Template
{
    protected function _toHtml()
    {
        $html="";
        $records = Mage::getModel('direcpay/database')->getCollection();
        foreach($records as $db_record){
        $html = $html . 'Order no : '.$db_record->getOrder_no().' Referecnce id : ';
        $html = $html . $db_record->getDirecpay_refid()."<br/>";
        }
        return $html;

希望这有助于某人。

相关问题