app/code/local/Info/news/Bock/Adminhtml/news/Grid.php
<?php
class Info_News_Block_Adminhtml_News_Grid extends Mage_Adminhtml_Block_Widget_Grid{
public function __construct(){
parent::__construct();
$this->setId('newsGridView');
$this->setDefaultSort('news_id');
$this->setDefaultDir('DESC');
$this->setSaveParametersInSession(true);
}
protected function _prepareCollection(){
//$collection=new Varien_Data_Collection();
$collection = Mage::getModel('news/news')->getCollection();
$this->setCollection($collection);
return parent::_prepareCollection();
}
protected function _prepareColumns(){
$this->addColumn("news_id",array(
"header"=>Mage::helper("news")->__("ID"),
"type"=>"number",
"index"=>"news_id"
));
$this->addColumn("news_title",array(
"header"=>Mage::helper("news")->__("Title"),
"type"=>"text",
"index"=>"news_title"
)); $this->addColumn("news_content",array(
"header"=>Mage::helper("news")->__("Content"),
"type"=>"text",
"index"=>"news_content"
));
}
}
app/code/local/Info/News/Model/News.php
<?php
class Info_News_Model_News extends Mage_Core_Model_Abstract{
protected function _construct() {
$this->_init('news/news');
}
}
app/code/local/Info/News/Model/Mysql4/News.php
<?php
class Info_News_Model_Mysql4_News extends Mage_Core_Model_Mysql4_Abstract{
protected function _construct() {
$this->_init('news/news','news_id');
}
}
app/code/local/Info/News/Model/Mysql4/News/Collection.php
<?php
class Info_News_Model_Mysql4_News_Collection extends Mage_Core_Model_Mysql4_Collection_Abstract{
public function _construct() {
parent::_construct();
$this->_init('news/news');
}
}
app/code/local/Info/News/Block/Adminhtml/News.php
<?php
class Info_News_Block_Adminhtml_News extends Mage_Adminhtml_Block_Widget_Grid_Container {
public function _construct (){
$this->_controller = 'adminhtml_news';
$this->_blockGroup = 'news';
$this->_headerText = Mage::helper('news')->__("Manage News");
parent::_construct();
}
}
app/code/local/Info/News/etc/config.xml
<config>
<modules>
<Info_News>
<version>
0.0.1
</version>
</Info_News>
</modules>
<admin>
<routers>
<news>
<use>admin</use>
<args>
<module>Info_News</module>
<frontName>admin_news</frontName>
</args>
</news>
</routers>
</admin>
<adminhtml>
<layout>
<updates>
<news>
<file>info/news.xml</file>
</news>
</updates>
</layout>
</adminhtml>
<global>
<models>
<news>
<class>
Info_News_Model
</class>
<resourceModel>
news_mysql4
</resourceModel>
</news>
<news_mysql4>
<class>
Info_News_Model_Mysql4
</class>
<entities>
<news>
<table>
info_news
</table>
</news>
</entities>
</news_mysql4>
</models>
<helpers>
<news>
<class>
Info_News_Helper
</class>
</news>
</helpers>
<blocks>
<news>
<class>
Info_News_Block
</class>
</news>
</blocks>
<resources>
<news_setup>
<setup>
<module>
Info_News
</module>
</setup>
<connection>
<use>
core_setup
</use>
</connection>
</news_setup>
<news_write>
<connection>
<use>
core_write
</use>
</connection>
</news_write>
<news_read>
<connection>
<use>
core_read
</use>
</connection>
</news_read>
</resources>
</global>
</config>
app/design/adminhtml/default/default/layout/info/news.xml
<?xml version="1.0"?>
<layout version="0.0.1">
<news_adminhtml_news_index>
<reference name="content">
<block type="news/adminhtml_news" name="news" />
</reference>
</news_adminhtml_news_index>
</layout>
This is my result