无法在magento中查看管理端的网格

时间:2014-01-29 07:20:35

标签: magento grid

尝试在magento的管理端开发一个模块,但无法在管理端看到网格。只需要显示定义的标签以及数据库中的数据。以下是与我的模块相关的代码,其中News是命名空间,Demo是模块名称。

与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>

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

$ this-&gt; _blockgroup =&#39; demo&#39;;

这里g应该是大写字母G,这是我面临的问题。

应该是这样的

$ this-&gt; _blockGroup =&#39; demo&#39;;