仿万能标签的万能函数//生成参数列表,以数组形式返回<br>
function mt_toarray($tag = ''){<br>
$param = array();<br>
$array = explode(';',$tag);<br>
foreach ($array as $v){<br>
list($key,$val) = explode(':',trim($v));<br>
$param[trim($key)] = trim($val);<br>
}<br>
return $param;<br>
}<br>
function getlist($tag){<br>
$list = array();<br>
$tag = mt_toarray($tag);<br>
$model =!empty($tag['model'])?$tag['model']:'';<br>
$limit =!empty($tag['limit'])?$tag['limit']:'10';<br>
$order =!empty($tag['order'])?$tag['order']:'';<br>
$field =!empty($tag['field'])?$tag['field']:'*';<br>
if($model == ""){return $list;}<br>
$M=M($model);<br>
if(!empty($tag['where'])){<br>
$wheres = explode(',',$tag['where']);<br>
foreach($wheres as $v){<br>
if(!empty($tag[$v])){<br>
$where[$v] = array('in',$tag[$v]);<br>
}<br>
}<br>
$M->where($where);<br>
}<br>
$list = $M->field($field)->order($order)->limit($limit)->select();<br>
return $list;<br>
}
使用例子<php>$list = getlist("model:article;where:cid;cid:1,2,3,4");</php>
上面这段就是取article表里面cid是1,2,3,4的内容 默认10条
模板写法就直接用官方的循坏写法<php>$list = getlist("model:article;where:cid;cid:1,2,3,4");</php>
我不是专业的,谅解。如果大家有能力就自己加上page 等其他功能。
{$vo.id}:{$vo.name}