[BUG] volist标签解析BUG

浏览:461 发布日期:2016/10/11 分类:ThinkPHP5专区 关键字: BUG
volist标签解析的时候,用 key 取模算奇偶数的时候,写了个 ++$key
导致数据在模板中显示的时候,输出 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; ?>';
最佳答案
评论( 相关
后面还有条评论,点击查看>>