您的位置:首页 > 其它

根据参数,输出产品个数

2011-11-21 12:04 49 查看
一般首页,是汇聚网站各个模块信息的集合。

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

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

其实方法很简单

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>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐