1
First write Controller
Public Function kunaction (){
$ This-> loadlayout ();
$ This-> _ addcontent ($ this-> getlayout ()-> createblock ('gao/manage_gao '));
$ This-> renderlayout ();
}
2
Write Block
APP/code/community/aq/GAO/block/manage/Gao. php
APP/code/community/aq/GAO/block/manage/GAO/grid. php
2.1
APP/code/community/aq/GAO/block/manage/Gao. php
<? PHP
Class aq_gao_block_manage_gao extends mage_adminhtml_block_widget_grid_container {
Public Function _ construct (){
// Use the generated path
$ This-> _ controller = 'Manage _ gao ';
// Module name
$ This-> _ blockgroup = 'gao ';
// Header title
$ This-> _ headertext = 'blog post manager ';
Parent: :__ construct ();
}
Protected function _ preparelayout (){
$ This-> setchild ('add _ new_button ',
$ This-> getlayout ()-> createblock ('adminhtml/widget_button ')
-> Setdata (Array (
'Label' => 'add Post ',
// The path to be executed after the button is pressed.
'Onclick' => "setlocation ('". $ this-> geturl (' */new ')."')",
'Class' => 'add'
))
);
// When there are multiple stores.
If (! Mage: APP ()-> issinglestoremode ()){
$ This-> setchild ('store _ switcher ',
$ This-> getlayout ()-> createblock ('adminhtml/store_switcher ')
-> Setuseconfirm (false)
-> Setswitchurl ($ this-> geturl ('*/*', array ('store' => null )))
);
}
// Specify the sub-block. Here the APP/code/community/aq/GAO/block/manage/GAO/grid. php
$ This-> setchild ('grid', $ this-> getlayout ()-> createblock ('gao/manage_gao_grid ', 'gao. grid '));
Return parent: _ preparelayout ();
}
}
2.2
APP/code/community/aq/GAO/block/manage/GAO/grid. php
The block is a sub-block of 2.1.
<? PHP
Class aq_gao_block_manage_gao_grid extends mage_adminhtml_block_widget_grid {
Public Function _ construct (){
Parent: :__ construct ();
//
$ This-> setid ('gaoge ');
// Sort by Time
$ This-> setdefaultsort ('created _ Time ');
// Sorting method
$ This-> setdefadir Dir ('desc ');
$ This-> setsaveparametersinsession (true );
}
Protected function _ getstore ()
{
$ Storeid = (INT) $ this-> getrequest ()-> getparam ('store', 0 );
Return Mage: APP ()-> getstore ($ storeid );
}
Protected function _ preparecollection ()
{
// Data loading
$ Collection = Mage: GetModel ('blog/blog')-> getcollection ();
$ Store = $ this-> _ getstore ();
If ($ store-> GETID ()){
$ Collection-> addstorefilter ($ store );
}
//
$ This-> setcollection ($ collection );
Return parent: _ preparecollection ();
}
Protected function _ preparecolumns (){
$ This-> AddColumn ('Post _ id', array (
'Header' => 'id ',
'Align '=> 'right ',
'Width' => '50px ',
'Index' => 'Post _ id ',
));
$ This-> AddColumn ('title', array (
'Header' => 'title ',
'Align '=> 'left ',
'Index' => 'title ',
));
// Echo "FDFD ";
Return parent: _ preparecolumns ();
}
// Click the path address for each row. And specify the output id value.
Public Function getrowurl ($ row)
{
Return $ this-> geturl ('*/edit', array ('id' => $ row-> GETID ()));
}
}