根据参数,输出产品个数

来源:互联网 发布:pt6.0设置trunk端口 编辑:程序博客网 时间:2024/06/09 21:20

一般首页,是汇聚网站各个模块信息的集合。

所以在首页中,每个内容块都要求输出部分内容,如新品,特色产品,热卖,秒杀,买家分享等

故需要做一个设置,来输出其产品个数。

其实方法很简单

1.在Block中添加以下内容,来限制突出条数

protected $_productsCount = null;const DEFAULT_PRODUCTS_COUNT = 5;public function setProductsCount($count)    {        $this->_productsCount = $count;        return $this;    }    /**     * Get how much products should be displayed at once.     *     * @return int     */    public function getProductsCount()    {        if (null === $this->_productsCount) {            $this->_productsCount = self::DEFAULT_PRODUCTS_COUNT;        }        return $this->_productsCount;    }

2.根据传入的参数来输出记录条数(在Collection的后面)

->setPageSize($this->getProductsCount())->setCurPage(1)

3.这样就可以在CMS中,传入相关参数,尽而输出内容数了

<block type="xxxx/xxxx" name="xxxx" template="xxxx/home.news.phtml"><action method="setProductsCount"><count>3</count></action></block>



原创粉丝点击