phpcms--使用添加php原生支持

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分配页面内容。这种方式也是我非常看好的方式。 

 

posted @ 2014-02-25 14:36  fsl  阅读(2402)  评论(0编辑  收藏  举报