#1 prince
我用这面这个查询:
$this -> results_caipu = $cpList -> findAll(null,'crDate DESC',null,"0,10");
在前台网页smarty显示的时候想只显示2到5条记录,如何实现?
2011-03-09 22:15:12
#2 coolcool1265
如果你不在查询中(controller)设置的话,在smarty中可以用smarty的变量控制显示的数量。
2011-03-10 08:10:07
#3 jake
楼上正解,在smarty中的foreach循环里面可以用index(0开始)和iteration (1开始)来进行当前条的判断来决定是否显示
http://www.smarty.net/docs/en/language.function.foreach.tplforeach.property.index
2011-03-10 08:35:44
#4 prince
<{section name=caipuThree loop=$results_caipu start=1 step=1 max=6 show=true}>
[
<{$results_caipu[caipuThree].cp_name|truncate:30:"...":true}>
]<{$results_caipu[caipuThree].modDate|truncate:11:""}>
<{/section}>smarty手册里的:
属性 类型 是否必须 缺省值 描述 name string Yes n/a 该循环的名称
loop [$variable_name] Yes n/a 决定循环次数的变量名称
start integer No 0 循环执行的初始位置. 如果该值为负数,开始位置从数组的尾部算起. 例如:如果数组中有7个元素,指定start为-2,那么指向当前数组的索引为5. 非法值(超过了循环数组的下限)将被自动调整为最接近的合法值.
step integer No 1 该值决定循环的步长. 例如指定step=2将只遍历下标为0、2、4等的元素. 如果step为负值,那么遍历数组的时候从后向前遍历.
max integer No 1 设定循环最大执行次数.
show boolean No true 决定是否显示该循环.
2011-03-12 15:01:08