当前位置:首页 » 编程语言 » 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 ,在模板里可以用的.有教程,自己找.

热点内容
java二进制读取 发布:2025-07-03 11:55:52 浏览:739
我的世界服务器记分板排版 发布:2025-07-03 11:39:22 浏览:569
安卓前期用什么处理器 发布:2025-07-03 11:37:54 浏览:870
如何更换安卓手机内存 发布:2025-07-03 11:18:52 浏览:57
魔兽清理缓存 发布:2025-07-03 10:46:38 浏览:521
神州防火墙web怎么配置代码 发布:2025-07-03 10:37:54 浏览:328
安卓看小说哪个软件免费又最好 发布:2025-07-03 10:25:30 浏览:437
linuxprofile 发布:2025-07-03 10:25:29 浏览:719
存储蓝盘 发布:2025-07-03 09:55:10 浏览:887
java必学 发布:2025-07-03 09:21:57 浏览:450