2012-05-01 189 views
0

我當前正在嘗試將塊添加到自定義Adminhtml模塊。我能夠顯示塊的內容,但是它以灰色背景在頁面的頂部呈現,然後是設計和菜單直接在底下呈現的標準magento佈局。將塊添加到magento adminhtml模塊

即時嘗試以正確的方式做事情,以瞭解最佳做法,並遵循書籍和教程以及magento核心,但迄今爲止一直無法正確添加內容。

到目前爲止,我有:

public function indexAction() 
{ 
    $this->loadLayout(); 
    $this->_setTitle(); 
    $main_block = new Invent_General_Block_Info(); 
    echo $main_block->toHtml(); 
    //$this->_addContent($main_block); 
    $this->renderLayout(); 

我能看到的一般方式在法師核心這樣做會是這樣的

/** 
    * Append customers block to content 
    */ 
    $this->_addContent(
     $this->getLayout()->createBlock('adminhtml/customer', 'customer') 
    ); 

,因爲我已經創建了塊$ main_block它對我來說沒有意義 - > createBlock,所以我不知道該從這裏做什麼。

像往常一樣讚賞任何幫助。謝謝!

回答

5

創建我發現,解決了這個問題的答案。

當然它會來自艾倫風暴。謝謝艾倫。線程被發現here

所以要解決這個問題,我所做的就是:

創建應用程序/設計文件夾/ adminhtml/mythemename/info.phtml

,然後在我的控制器動作我根本:

$this->loadLayout(); 
    $this->_setTitle(); 
$this->_addContent($this->getLayout()->createBlock('adminhtml/template')->setTemplate('shipment/info.phtml')); 
    $this->renderLayout(); 

它工作的很棒。

0

使用此如果靜態塊您通過CMS

/** 
    * Append customers block to content 
    */ 

$this->_addContent(
    $this->getLayout() 
    ->createBlock('cms/block') 
    ->setBlockId('{block_name}') 
    ->toHtml() 
); 
+0

嗨感謝您的建議,但這並沒有奏效,因爲我沒有通過CMS創建塊,但已經這樣編程。 – activeDev