syylr / thinkphp

Automatically exported from code.google.com/p/thinkphp
0 stars 0 forks source link

volist只有offset属性的时候,生成的php代码不正确 #10

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

我的理解当volist写成如下的时候
<volist name="brand" id="item" offset="$offset"> 
循环是从offset到array结束。

而框架生成的php代码如下,
<?php if(is_array($brand)): $i = 0; $__LIST__ = 
array_slice($brand,$offset,count($__LIST__),true);
截取array的长度确依赖一个在作用域未赋值的变量__LIST__

What is the expected output? What do you see instead?
<?php if(is_array($brand)): $i = 0; $__LIST__ = 
array_slice($brand,$offset,count($brand),true);

What version of the product are you using? On what operating system?
Thinkphp 3.0

Please provide any additional information below.

详见TabLibCx.class.php:_volist()

        if(isset($tag['length']) && '' !=$tag['length'] ) {
            $parseStr  .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].','.$tag['length'].',true);';
        }elseif(isset($tag['offset'])  && '' !=$tag['offset']){
            $parseStr  .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].',count($__LIST__),true);';
        }else{
            $parseStr .= ' $__LIST__ = '.$name.';';
        }

Original issue reported on code.google.com by kane.mx on 14 Apr 2012 at 9:55

GoogleCodeExporter commented 8 years ago
应该是改成,

<?php if(is_array($brand)): $i = 0; $__LIST__ = 
array_slice($brand,$offset,count($brand)-$offset,true);

offset是正数的情况下,从offset到数组最后一个元素。

offset是负数,
<?php if(is_array($brand)): $i = 0; $__LIST__ = 
array_slice($brand,$offset,count($brand)+$offset,true);

Original comment by kane.mx on 14 Apr 2012 at 2:46