导致数据在模板中显示的时候,输出 key 的值错误(如原来的key是字母b,输出的时候就变成了c,因为 ++了)
错误代码在
/thinkphp/library/think/template/taglib/Cx.php
line: 101
$parseStr .= 'if(is_array(' . $name . ') || ' . $name . ' instanceof \think\Collection): $' . $key . ' = 0;';
修改的话,可以重新用一个变量,比如 $modKey 专门用来取模算奇偶数。line 101 to line 114 可以修改为:
$modKey = "modKey";
$parseStr .= 'if(is_array(' . $name . ') || ' . $name . ' instanceof \think\Collection): $' . $modKey . ' = 0;';
// 设置了输出数组长度
if (0 != $offset || 'null' != $length) {
$parseStr .= '$__LIST__ = is_array(' . $name . ') ? array_slice(' . $name . ',' . $offset . ',' . $length . ', true) : ' . $name . '->slice(' . $offset . ',' . $length . ', true); ';
} else {
$parseStr .= ' $__LIST__ = ' . $name . ';';
}
$parseStr .= 'if( count($__LIST__)==0 ) : echo "' . $empty . '" ;';
$parseStr .= 'else: ';
$parseStr .= 'foreach($__LIST__ as $key=>$' . $id . '): ';
$parseStr .= '$mod = ($' . $modKey . ' % ' . $mod . ' );';
$parseStr .= '++$' . $modKey . ';?>';
$parseStr .= $content;
$parseStr .= '<?php endforeach; endif; else: echo "' . $empty . '" ;endif; ?>';
最佳答案
