Select All -- grid control -- magento query all information in the background

Source: Internet
Author: User

 

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 ()));

}

 

 

}

 

 

 

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.