Skip to content

Commit 7d7e682

Browse files
author
zuojiazi.cn@gmail.com
committed
修正了for循环标签嵌套变量冲突的问题
git-svn-id: http://thinkphp.googlecode.com/svn/trunk@2979 539fd3ec-2725-0410-b7ab-251e373a8e33
1 parent 48a8cbd commit 7d7e682

File tree

1 file changed

+3
-2
lines changed

1 file changed

+3
-2
lines changed

ThinkPHP/Lib/Driver/TagLib/TagLibCx.class.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -690,6 +690,7 @@ public function _for($attr, $content){
690690
$step = 1;
691691
$comparison = 'lt';
692692
$name= 'i';
693+
$rand = rand(); //添加随机数,防止嵌套变量冲突
693694
//获取属性
694695
foreach ($this->parseXmlAttr($attr, 'for') as $key => $value){
695696
$value = trim($value);
@@ -706,8 +707,8 @@ public function _for($attr, $content){
706707
}
707708
}
708709

709-
$parseStr = '<?php $__FOR_START__='.$start.';$__FOR_END__='.$end.';';
710-
$parseStr .= 'for($'.$name.'=$__FOR_START__;'.$this->parseCondition('$'.$name.' '.$comparison.' $__FOR_END__').';$'.$name.'+='.$step.'){ ?>';
710+
$parseStr = '<?php $__FOR_START_'.$rand.'__='.$start.';$__FOR_END_'.$rand.'__='.$end.';';
711+
$parseStr .= 'for($'.$name.'=$__FOR_START_'.$rand.'__;'.$this->parseCondition('$'.$name.' '.$comparison.' $__FOR_END_'.$rand.'__').';$'.$name.'+='.$step.'){ ?>';
711712
$parseStr .= $content;
712713
$parseStr .= '<?php } ?>';
713714
return $parseStr;

0 commit comments

Comments
 (0)