select All ------grid控件----magento后台查询所有信息

 

1

 

首先写controller

public function kunAction(){

$this->loadLayout();

$this->_addContent($this->getLayout()->createBlock('gao/manage_gao'));

 

$this->renderLayout();

 

}

2

编写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(){

//生成路径使用

$this->_controller = 'manage_gao';

//模块名字

$this->_blockGroup = 'gao';

//头标题

$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',

//按钮按下后执行的路径。

'onclick'=>"setLocation('".$this->getUrl('*/*/new')."') ",

'class' =>'add'

))

 

 

);

//多商店情况下。

if (!Mage::app()->isSingleStoreMode()) {

            $this->setChild('store_switcher',

                $this->getLayout()->createBlock('adminhtml/store_switcher')

                    ->setUseConfirm(false)

                    ->setSwitchUrl($this->getUrl('*/*/*', array('store'=>null)))

            );

        }

//子block指定。这里指定的就是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

 

此block为2.1的子block

 

<?php

 

class AQ_Gao_Block_Manage_Gao_Grid extends Mage_Adminhtml_Block_Widget_Grid{

public function __construct(){

 

parent::__construct();

//

$this->setId('gaoGrid');

//按时间排序

$this->setDefaultSort('created_time');

//排序方式

$this->setDefaultDir('DESC');

$this->setSaveParametersInSession(true);

 

}

protected function _getStore()

    {

        $storeId = (int) $this->getRequest()->getParam('store', 0);

        return Mage::app()->getStore($storeId);

    }

 

 

protected function _prepareCollection()

{

//数据的加载

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

 

 

}

//点击其中的每行访问的路径地址。并指定传出的ID值。

public function getRowUrl($row)

{

return $this->getUrl('*/*/edit', array('id' => $row->getId()));

}

 

 

}

 

 

 

 

 

 

 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值