2014-01-29 61 views
0

嘗試在管理端在magento中開發一個模塊,但無法在管理端查看網格。只需要在顯示網格的同時使用數據庫中的數據定義標籤。以下是與我的模塊相關的代碼,其中News是命名空間,Demo是模塊名稱。無法在magento中的管理端查看網格

有關indexController.php

<?php 
    class News_Demo_AdminHtml_IndexController extends Mage_Adminhtml_Controller_Action 
    { 
     protected function _initAction() 
     { 
      $this->loadLayout()->_setActiveMenu('demo/set_time') 
       ->_addBreadcrumb('test Manager','test Manager'); 
      //echo "<pre>"; print_r($this);echo "</pre>";exit; 
      return $this; 
     } 
     public function indexAction() 
     { 
      $this->_initAction(); 
      $this->renderLayout(); 
     }   
    } 
?> 

有關網格容器

class News_Demo_Block_Adminhtml_Grid extends Mage_Adminhtml_Block_Widget_Grid_Container 
{ 
    public function __construct() 
    { 
     $this->_controller = 'adminhtml_demo'; 
     $this->_blockgroup = 'demo'; 
     $this->_headerText = 'News Management'; 
     $this->_addButtonLabel = 'Add News'; 
     parent::__construct(); 
    } 
} 

到grid.php其中顯示網格相關的代碼代碼代碼。

<?php 

class News_Demo_Block_Adminhtml_Demo_Grid extends Mage_Adminhtml_Block_Widget_Grid 
{ 
    public function __construct() 
    { 
     parent::__construct(); 
     $this->setId('newsGrid'); 
     $this->setDefaultSort('id'); 
     $this->setDefaultDir('ASC'); 
     $this->setSaveParametersInSession(true); 
    } 
    protected function _prepareCollection() 
    { 
     $collection = Mage::getModel('demo/demo')->getCollection(); 
     $this->setCollection($collection); 
     return parent::_prepareCollection(); 
    } 
    protected function _prepareColumns() 
    { 
     $this->addColumn('id', 
      array(
       'header' => 'ID', 
       'align' =>'right', 
       'width' => '50px', 
       'index' => 'id_pfay_test', 
      )); 
     $this->addColumn('title', 
      array(
       'header' => 'Title', 
       'align' =>'left', 
       'index' => 'title', 
      )); 
     $this->addColumn('description', array(
      'header' => 'Description', 
      'align' =>'left', 
      'index' => 'description', 
     )); 
     $this->addColumn('createdDate', array(
      'header' => 'Date', 
      'align' =>'left', 
      'index' => 'createdDate', 
     )); 
     $this->addColumn('img', array(
      'header' => 'Image', 
      'align' =>'left', 
      'index' => 'img', 
     )); 
     return parent::_prepareColumns(); 
    } 
    public function getRowUrl($row) 
    { 
     return $this->getUrl('*/*/edit', array('id' => $row->getId())); 
    } 
} 
?> 

代碼有關config.xml中

<?xml version="1.0"?> 

    <config> 
     <modules> 
      <News_Demo> 
       <version>1.0.0</version> 
      </News_Demo> 
     </modules> 

     <frontend> 
      <routers> 
       <news> 
        <use>standard</use> 
        <args> 
         <module>News_Demo</module> 
         <frontName>news</frontName> 
        </args> 
       </news> 
      </routers> 
      <layout> 
       <updates> 
        <news_demo> 
         <file>demo.xml</file> 
        </news_demo> 
       </updates> 
      </layout> 
     </frontend> 

     <admin> 
      <routers> 
       <demo> 
        <use>admin</use> 
        <args> 
         <module>News_Demo</module> 
         <frontName>adminnews</frontName> 
        </args> 
       </demo> 
      </routers> 
     </admin> 
     <adminhtml> 
      <layout> 
       <updates> 
        <demo> 
         <file> 
          demo.xml 
         </file> 
        </demo> 
       </updates> 
      </layout> 
      <menu> 
       <demo translate="title" module="adminhtml"> 
        <title>News</title> 
        <sort_order>100</sort_order> 
        <children> 
         <set_time> 
          <title>Add News</title> 
          <action>adminnews/adminhtml_index</action> 
         </set_time> 
        </children> 
       </demo> 
      </menu> 
     </adminhtml> 

     <global> 
      <blocks> 
       <demo> 
        <class>News_Demo_Block</class> 
       </demo> 
      </blocks> 
      <!--<models> 
       <news_demo> 
        <class>News_Demo_Model</class> 
        <resourceModel>news_demo_mysql4</resourceModel> 
       </news_demo> 
       <news_demo_mysql4> 
        <class>News_Demo_Model_Mysql4</class> 
        <entities> 
         <news_demo> 
          <table>news_demo</table> 
         </news_demo> 
        </entities> 
       </news_demo_mysql4> 
      </models>--> 
      <models> 
       <demo> 
        <class>News_Demo_Model</class> 
        <resourceModel>demo_mysql4</resourceModel> 
       </demo> 
       <demo_mysql4> 
        <class>News_Demo_Model_Mysql4</class> 
        <entities> 
         <demo> 
          <table>demo_news</table> 
         </demo> 
        </entities> 
       </demo_mysql4> 
      </models> 
    </global> 
</config> 

回答

0

在adminhtml佈局添加模塊設計佈局,並給予名稱,如demo.xml

<?xml version="1.0"?> 
<layout version="0.1.0"> 
    <demo_adminhtml_demo_index> 
     <reference name="content"> 
      <block type="{Your grid block}" name="demo" /> 
     </reference> 
    </demo_adminhtml_demo_index> 
</layout> 
+0

感謝您的回覆......我已經這樣做了,但沒用...... – devJsha

0

$這個 - > _blockgroup ='demo';

這裏g應該是大寫字母G,這是我面臨的問題。

它應該是這樣的

$此 - > _ blockGroup = '示範';