当前位置:首页 » 编程语言 » php自定义标签

php自定义标签

发布时间: 2024-09-25 05:25:04

A. php 入口文件都配置好了的,但是用<a>跳转后 action="<{spUrl c=main a=save}>" 就没用起smarty,把路径解

smarty模版变量没法解析,不知道那些是变量?
应该这样:在php文件里:
$smarty=new Smarty();
$smarty->Assign("spurl",$spurl);
...
...
$smarty->display("/main.html");
模版文件里这样:
<a href="dest.php?action=<{$spurl}>&c=main&a=save">click here</a>

B. thinkphp3.2.3自定义标签问题

需要自己先定义好,定义方法:

项目文件夹

新建一个文件,例如 Tp.class.php

<?php

namespaceThinkTemplateTagLib;

useThinkTemplateTagLib;

classTpextendsTagLib{

protected$tags=array(
'list'=>array('attr'=>'order,limit','close'=>1),
'webinfo'=>array('close'=>1),//1=<webinfo><webinfo/>
);

publicfunction_list($attr,$content){
$order=$attr['order'];//排序
$limit=$attr['limit'];//多少条数据

$str='<?php';
$str.='$result=M()->table(array("m_article"=>"article","m_menu"=>"menu","m_web_admin"=>"admin"))->field("article.*,menu.nameasmenu,admin.nameasauthor")->where("article.mid=menu.idandarticle.uid=admin.id")->order("'.$order.'")->limit('.$limit.')->select();';
$str.='foreach($resultas$v):';
$str.='?>';
$str.=$content;
$str.='<?phpendforeach?>';

return$str;
}

publicfunction_webinfo($attr='',$content){
$str='<?php';
$str.='$result=M("web_set")->where("id=1")->select();';
$str.='foreach($resultas$k=>$ii):';
$str.='?>';
$str.=$content;
$str.='<?phpendforeach?>';
return$str;
}}

两个示例都是固定了数据表,可以根据自己的需要更改,或者直接做成变量,前台使用的时候再传入。

第二步,在config文件中写下如下代码:

'TAGLIB_BUILD_IN' => 'Cx,Tp'


然后在模版中调用:

<!--webinfo使用方法-->
<webinfo>
<{$ii.web_name}>
</webinfo>

<!--list使用方法-->
<listlimit="10"order="iddesc">
<{$v.menu}>
</list>



M-finder博客:http://www.m-finder.com/,长期分享技术相关知识,欢迎大家访问

C. phpcms怎样使用自定义sql语句调用标签

那叫 get ,在模板里可以用的.有教程,自己找.

热点内容
大容量存储盒评测 发布:2025-07-03 20:14:58 浏览:159
死锁贪心算法 发布:2025-07-03 20:14:47 浏览:39
算法项目目标 发布:2025-07-03 19:47:07 浏览:768
手机开屏密码多少 发布:2025-07-03 19:35:48 浏览:801
我的世界梦世界服务器怎么重启 发布:2025-07-03 19:33:20 浏览:545
编译型语言快 发布:2025-07-03 19:31:57 浏览:414
mud服务器搭建 发布:2025-07-03 19:28:37 浏览:496
云存储空间怎么缴费 发布:2025-07-03 19:22:45 浏览:637
双机热备虚拟ip怎么配置域名 发布:2025-07-03 19:09:18 浏览:356
计算数据存储地址 发布:2025-07-03 18:48:29 浏览:714