处理头尾是经常的事
找到 ThinkPHP\Library\Think\Template\TagLib\Cx.class.php
找到 _volist 方法 替换成下面代码(本人写的代码比较粗,看官们勿笑)public function _volist($tag,$content) {<br>
$name = $tag['name'];<br>
$id = $tag['id'];<br>
$empty = isset($tag['empty'])?$tag['empty']:'';<br>
$key = !empty($tag['key'])?$tag['key']:'i';<br>
$mod = isset($tag['mod'])?$tag['mod']:'2';<br>
// 允许使用函数设定数据集 <volist>{$vo.name}</volist><br>
$parseStr = '<?php ';<br />
// $parseStr = '$length=count('.$name.') ';<br>
if(0===strpos($name,':')) {<br>
$parseStr .= '$_result='.substr($name,1).';';<br>
$name = '$_result';<br>
}else{<br>
$name = $this->autoBuildVar($name);<br>
}<br>
$parseStr .= 'if(is_array('.$name.')): $'.$key.' = 0;';<br>
if(isset($tag['length']) && '' !=$tag['length'] ) {<br>
$parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].','.$tag['length'].',true);';<br>
}elseif(isset($tag['offset']) && '' !=$tag['offset']){<br>
$parseStr .= ' $__LIST__ = array_slice('.$name.','.$tag['offset'].',null,true);';<br>
}else{<br>
$parseStr .= ' $__LIST__ = '.$name.';';<br>
}<br>
$parseStr .= '$is_first=false;$is_last=false;$_key=0;$length=count($__LIST__);';<br>
$parseStr .= 'if( count($__LIST__)==0 ) : echo "'.$empty.'" ;';<br>
$parseStr .= 'else: ';<br>
$parseStr .= 'foreach($__LIST__ as $key=>$'.$id.'): ';<br>
$parseStr .= 'if($_key==0) : $is_first=true; else :$is_first=false;endif;';<br>
$parseStr .= 'if($_key==($length-1)) :$is_last=true; else :$is_last=false;endif;';<br>
$parseStr .= '$_key++;';<br>
$parseStr .= '$mod = ($'.$key.' % '.$mod.' );';<br>
$parseStr .= '++$'.$key.';?>';<br>
$parseStr .= $this->tpl->parse($content);<br>
$parseStr .= '<?php endforeach; endif; else: echo "'.$empty.'" ;endif; ?>';<br>
<br>
if(!empty($parseStr)) {<br>
return $parseStr;<br>
}<br>
return ;<br>
}
模板中<volist><br>
<li>{$vo.value}<br>
<eq>______这是第一条</eq><br>
<eq>______这是最后一条</eq><br>
</li>
<br>
</volist>
如有错误,请告知 398235105@qq.com
AD:真正免费,域名+虚机+企业邮箱=0元