2011-06-23 71 views
2

如果我必须从数据库中显示一些数据,我该如何在管理控制器中传递这些数据?说我定义在我的控制器块如何显示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()从自定义表中检索数据并显示它。当我尝试了这一点,我看到的数据在页面的顶部,而不是在内容块。

如何将其显示在内容块中?谢谢。

+0

我假设你写了新模块。你有没有创建管理页面?我的意思是你是否已经创建了控制器和布局更新? – Zyava

+0

是的,我有一个新的模块。我有从db获取我的数据的控制器。我没有布局,因为我不知道如何。我知道我必须通过块显示内容,但不知道如何。 – Nithin

回答

4

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

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

这是我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; 

希望这可以帮助别人。

相关问题