phpcms--使用新增php原生支援

fsl發表於2014-02-25

1,phpcms模板中有時候要新增一些php相關變數這個時候要使用原始php的東西,可以如下加入

{php $no_wq_id=$r[id] ;}其中$r[id]是通過{pc:get sql="..."}的loop迴圈得到的

新增欄目陣列

{php $my_arr=array('1'=>'aaa','3'=>'bbbb','4'=>'cccc','15'=>'dddd', } 有時候你麼辦法在一個頁面呼叫其他欄目或使用多層巢狀這個使用可以預呼叫(或者手寫硬編碼)一個欄目陣列然後再如下,配合呼叫

{$my_arr[$r[catid]]}

如果你對陣列使用比較多一定明白這種關聯陣列的好處,別為巢狀發愁了。

 2,也可以使用php標記直接插入模板進行使用

<?php 

$uid=param::get_cookie('_userid'); if(is_array($_GET)&&count($_GET)>0)//先判斷是否通過get傳值了 { if(isset($_GET["catid"]))//是否存在"caatid"的引數 { if($_GET["catid"]==19){$sql="select * from ec_changdix_data as b where a.id=b.id and userid=$uid and status=99 and catid in (20,21,22)";} if($_GET["catid"]==23){$sql="select * from ec_changdix as a , ec_changdix_data as b where a.id=b.id and userid=$uid and status=99 and catid=23";} }else{$sql="select * from ec_changdix as a , ec_changdix_data as b where a.id=b.id and userid=$uid and status=99 and catid in (20,21,22,23)";}
}
?> {ec:get sql="$sql" num="100"} {loop $data $info}

 

 

 

3,其實除了在服務端一次完成相關資料呼叫這種方式外,現在流行的ajax方式也非常方便,比如一個頁面區域需要呼叫一下資料,這些資料在模板中沒法方便的寫出程式碼,這是使用php原始功能寫一個頁面通過jquery的的load函式直接載入就可以。

<div id="dwdw"></div>
<script>
$(document).ready(function(){

$("#dwdw").load("{$r[url]} #dftx");

});

</script>

效果剛剛的。

當然如果你的js水平出神入化,你也可以分表呼叫所需陣列,最後使用js分配頁面內容。這種方式也是我非常看好的方式。 

 

相關文章