magento paginate a custom collection

前端 未结 1 437
粉色の甜心
粉色の甜心 2021-01-22 08:16

I have a custom page where I have displayed custom products using custom queries by crossing models against brands. I have an array of products Ids now what I can\'t seem to fig

1条回答
  •  挽巷
    挽巷 (楼主)
    2021-01-22 08:53

    Step 1: Controller (IndexController.php) file In index controller simply load the layout and render it.

    loadLayout();
            $this->renderLayout();
        }
    }
    ?>
    

    Step 2: Layout (custom.xml) file Put the under given code in the layout file of module.

    
    
       
           
               
           
       
    
    

    here is code for block where you can define collection

    getCollection();
            $this->setCollection($collection);
        }
    
        protected function _prepareLayout()
        {
            parent::_prepareLayout();
    
            $pager = $this->getLayout()->createBlock('page/html_pager', 'custom.pager');
            $pager->setAvailableLimit(array(5=>5,10=>10,20=>20,'all'=>'all'));
            $pager->setCollection($this->getCollection());
            $this->setChild('pager', $pager);
            $this->getCollection()->load();
            return $this;
        }
    
        public function getPagerHtml()
        {
            return $this->getChildHtml('pager');
        }
    }
    

    you have to define custom collection which return the product id as per your requirement.in above code here is the phtml file where you can get pagination

    getMessagesBlock()->getGroupedHtml() ?>
    getCollection(); ?>
    

    __('My Custom Collection') ?>

    getPagerHtml(); ?> getSize()): ?>
    __('ID #') ?> __('Title') ?> __('Created') ?>
    getCollectionId() ?> getTitle(); ?> formatDate($_obj->getCreatedTime()) ?>
    getPagerHtml(); ?>

    __('The collection is empty.'); ?>

    hope this will help you

    0 讨论(0)
提交回复
热议问题