如果我必须显示数据库中的一些数据,我如何在管理控制器中传递这些数据?假设我在控制器中定义了一个块
$block = $this->getLayout()->createBlock('core/text')->setText('<h1>Main Block</h1>');
Run Code Online (Sandbox Code Playgroud)
我可以将任何类型的数据传递给 setText() 函数以在管理页面中显示我需要的数据还是有其他函数?我想从后端的自定义表中显示一些订单号。
我试过这样的事情: $block = $this->getLayout()->createBlock('core/text')->setText('<h1>Main Block</h1><div>'.$this->showAllRecordsAction().'</div>');
showAllRecordsAction() 从自定义表中检索数据并显示它。当我尝试这个时,我看到页面顶部的数据而不是内容块中的数据。
如何在内容块中显示它?谢谢。
我能够通过块显示内容。在我的 indexController 中使用了此代码:
$this->loadLayout();
$this->_addContent($this->getLayout()->createBlock('adminhelloworld/view'))
->renderLayout();
Run Code Online (Sandbox Code Playgroud)
这是我在 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;
Run Code Online (Sandbox Code Playgroud)
希望这可以帮助某人。