/*
*******************************************
*内容分类标签
*******************************************
* 类型 |属性名称| 功能 | 值说明 | 是否必须
* number| mid | 模型ID | 默认全部 | 否
* number| cid | 栏目ID |多个以逗号分割| 否
* number| pid | 上级ID |多个以逗号分割| 否
* number| limit | 条数 | limit='10' | 否
* string| order | 排序 | | 否
* string| where |附加条件| 同SQL | 否
* 使用where mid cid pid均失效
*/
public function _list($attr,$content){
$cateGory_field_id =$attr['id'];//返回ID
$prefix = 'category';//表前缀
$str.=<<<etc
<?php
function loop(\$key,\$value,\$prefix)
{
\$data = \$prefix.".\$key";//前缀
if(strpos(\$value, ","))
{
\$arrValue = explode(",", \$value);
foreach (\$arrValue as \$key=>\$val)
{
\$map[\$key] = \$data.'='.\$val;
}
}else{
\$map[] = \$data.'='.\$value;
}
\$map['_logic'] ='OR';
return \$map ;
}
?>
etc;
if(!empty($attr['mid'])){
$str.="<?php $".map."[] = loop('model_id','$attr[mid]',$prefix); ?>";
};
if(!empty($attr['cid'])){
$str.="<?php $".map."[] = loop('cat_id','$attr[cid]',$prefix); ?>";
};
if(isset($attr['pid'])){
$str.="<?php $".map."[] = loop('pcat_id','$attr[pid]',$prefix); ?>";
}
if(!empty($attr['where'])){
unset($map);
$map[] =$attr['where'];
}
if(!empty($attr['limit'])){
$limit = "limit=".$attr['limit'];
$limit=substr($limit,6);
}
if(!empty($attr['order'])){
$order = $attr['order'];
}
$str .='<?php $category=D(Category);?>';
$str .='<?php $cateGory_string=$category->where($map)->limit("'.$limit.'")->order("'.$order.'")->select(); ?>';
$str .= '<?php foreach ($cateGory_string as $key => $'.$cateGory_field_id.'): ?>';
$str .=$this->tpl->parse($content);
$str .= '<?php endforeach; ?>';
return $str;
} 上面是我自定义的标签,一层功能能够实现,但是我要嵌套的话,$content就直接打印出来,不会再循环。请问怎么解决
最佳答案