尝试在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>发布于 2014-01-29 08:31:02
在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>发布于 2014-06-27 12:46:18
$this->_blockgroup = 'demo';
这里的g应该是大写的G,这就是我所面临的问题。
应该是这样的
$this->块组=‘演示’;
https://stackoverflow.com/questions/21424584
复制相似问题