magento中对获取的数据在前台进行分页显示
1.数据加载类
class Bf170_Bf170Logistics_Block_Inquiry_Index extends Mage_Core_Block_Template {
public function __construct(){
parent::__construct();
$account = new Varien_Object();
$recordCol = new Varien_Data_Collection();//这个对象和加载数据的对象是同一个
$customer = Mage::getSingleton( 'customer/session' )->getData('id');
if(!!$customer){
// 获取用户已经完款的订单
$recordCol = Mage::getModel('sales/order_shipment_track')->getCollection();
$orderAddressTableName = Mage::getSingleton('core/resource')->getTableName('sales/order');
$recordCol->getSelect()->joinLeft(
array('order' => $orderAddressTableName),
"main_table.order_id = order.entity_id",
array(
'increment_id'=>'order.increment_id'
)
)->where('customer_id=?',$customer);
}
$this->setRecordCol($recordCol);
}
protected function _prepareLayout(){
parent::_prepareLayout();
$pagerBlock = $this->getLayout()->createBlock('page/html_pager', 'bf170logistics.inquiry.index.pager');//这里是需要渲染的页面
$pagerBlock->setCollection($this->getRecordCol());//这里需要把$this->setRecordCol($recordCol);拿出来
$this->setChild('pager', $pagerBlock);
$this->getRecordCol()->load();
return $this;
}
public function getPagerHtml() {
return $this->getChildHtml('pager');
}
}