仿萬能標籤的萬能函數//產生參數列表,以陣列形式傳回<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}