在Magento分页作品第一次完美然后崩溃

时间:2015-01-31 05:25:49

标签: php magento pagination

我需要从数据库中搜索一个类别。

如果我第一次搜索它会显示正确的搜索结果。

当我在分页中单击下一个按钮时它将显示数据库中的所有数据。

我不知道为什么......请帮助我

在我的category.php文件中,编码是

<?php

class Magecart_Categories_Block_Categories extends Mage_Core_Block_Template
{
    public function __construct()`enter code here`
    {
        parent::__construct();
        $params = $this->getRequest()->getParams();
        $keyword = $params['keyword'];
        $id = $params['category'];
        $keyword = "%$keyword%";
        $id = "%$id%";
        $datasets = Mage::getModel("listings/listings")->getCollection()
        ->addFieldToSelect('*')
       ->addFieldToFilter('title',array('like' => $keyword))
       ->addFieldToFilter('cat_ids',array('like'=>$id));
        $this->setCollection($datasets);
    }


    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');
    }

    public function getItemsList()
    {
        $current_category = Mage::registry("current_category");
        $params = $this->getRequest()->getParams();
        return $listCollection = Mage::getModel("listings/listings")->getCategoryItems($current_category->getData('category_id'));
    }

    public function getSearchResults()
    {

        $params = $this->getRequest()->getParams();
        $keyword = $params['keyword'];
        $id = $params['category'];
        $keyword = "%$keyword%";
        $id = "%$id%";
        return $listCollection = Mage::getModel("listings/listings")->getCollection()
            ->addFieldToSelect('*')
            ->addFieldToFilter('title', array('like' => $keyword))
            ->addFieldToFilter('cat_ids', array('like' => $id));
    }

}

在我的search.phtml文件中,代码将是

<?php echo $this->getMessagesBlock()->getGroupedHtml() ?>
<?php $collection = $this->getCollection();
<div class="grid-9 cat-left">
    <?php echo $this->getPagerHtml(); ?>
    <div style="padding-left: 0;" class="grid-12">
        <?php

        $i = 1;
        if (count($collection) > 0) { ?>
            <?php foreach ($collection as $res) {
                $value = $res['value'];
                $resign = unserialize($value);
                $last = "";
                if ($i % 3 == 0) {
                    $last = "last";
                }
                ?>
                <div class="grid-4 clear <?php echo $last ?>">
                    <div class="content_grid">
                        <a href="<?php echo $baseUrl . "list/" . $res['url_key']; ?>">
                            <div style="overflow:hidden; padding:0px;" class="grid-12">
                                <img
                                    src="<?php echo $this->getBaseUrl() ?>media/images/listings/images/<?php echo $res['image1']; ?>"
                                    class="content_grid_img grow-rotate">
                            </div>
                        </a>

                        <div class="content_grid_text text-center">
                            <h3><?php echo $res['title']; ?></h3>

                            <div style="display: none;" class="address">
                                <p><?php echo $resign['48'] ?></p>
                            </div>
                            <div style="display: none;" class="contact">
                                <p><?php echo $resign['49'] ?></p>
                            </div>
                            <ul class="view_detail">
                                <li>
                                    <button class="addr"><i class="fa fa-home"></i></button>
                                </li>
                                <li>
                                    <a class=" view" href="<?php echo $baseUrl . "list/" . $res['url_key']; ?>">View
                                        Details
                                        <i class="fa fa-arrow-right"></i>
                                    </a>
                                </li>
                                <li>
                                    <button class="con"><i class="fa fa-phone"></i></button>
                                </li>
                            </ul>
                        </div>
                    </div>
                </div>

                <?php $i++;
            }
        } else {
            ?>
            <div class="no-products">
                <p>There is no product in this category</p>
            </div>
        <?php }
        ?>

    </div>
</div>

提前感谢!!

0 个答案:

没有答案