dede的万能标签好厉害,这里也弄个 AD:真正免费,域名+虚机+企业邮箱=0元
之前在论坛中也发过,现在在这里也发个,比上次的版本添加了,缓存,调试,field等..
foo是什么意义通俗点就是无法识别,一塌糊涂的意思,就是没意义。
这个没意义好有万能的意味,姑且使用foolist吧。
至于万能标签的意义呢,懒人必备,cms必备啊
官方的volist是要在action中定义数据来源的,foolist就厉害了,无需定义鸟:
foolist也是一个CX标签,
修改Lib\Driver\TagLib\TagLibCx.class.php
添加标签定义://一下为自定义<br>
'foolist' => array('attr'=>'model,where,order,num,id,page,pagesize,query,flag,field,cache','level'=>3), //万能的输出标签
好了下面是foolist 的内容<?php <br />
//by 无语西风<br>
// Lib/Driver/TagLid/TagLiCx.class.php <br>
//万能标签 <foolist><br>
//'foolist'=>array('attr'=>'model,where,order,num,id,page,pagesize,query,flag,debug','level'=>3), //万能的输出标签<br>
public function _foolist($attr,$content)<br>
{<br>
$html=''; <br>
$tag = $this->parseXmlAttr($attr,'foolist'); <br>
$model =!empty($tag['model'])?$tag['model']:''; <br>
$order =!empty($tag['order'])?$tag['order']:'';<br>
$num =!empty($tag['num'])?$tag['num']:'';<br>
$id =!empty($tag['id'])?$tag['id']:'d';<br>
$where =!empty($tag['where'])?$tag['where']:'';<br>
//使where支持 条件判断,添加不等于的判断 <br>
$this->comparison['noteq']= '';<br>
$this->comparison['sqleq']= '=';<br>
$where =$this->parseCondition($where); <br>
$page=false;<br>
if(!empty($tag['page'])) $page=$tag['page'];<br>
if($page=='ture') $page=false; <br>
$pagesize =!empty($tag['pagesize'])?$tag['pagesize']:'10';<br>
//是否用缓存,默认是false<br>
$cache =!empty($tag['cache'])?$tag['cache']:false;<br>
$query =!empty($tag['query'])?$tag['query']:'';<br>
$field =!empty($tag['field'])?$tag['field']:'';<br>
$debug =!empty($tag['debug'])?$tag['debug']:false;<br>
//使query 支持条件判断<br>
$query =$this->parseCondition($query); <br>
if($where!='') $where.=' and '.$flag; <br>
$html.='<?php $m=D("'.$model.'");';<br />
//如果使用了query,将忽略使用where,num,order,page,field,cache 等,使用query无法实现分页<br>
if($query){ <br>
if($cache!=false){<br>
$html.='$cache_key="key_".md5("'.$query.'");';<br>
$html.='if(!$ret=S($cache_key)){ $ret=$m->query("'.$query.'");S($cache_key,$ret);}';<br>
}else{<br>
$html.='$ret=$m->query("'.$query.'");';<br>
} <br>
}<br>
//如果使用了分页,缓存也不生效<br>
if($page && !$query){<br>
$html.='import("@.Common.Page"); '; //这里改成你的Page类 <br>
$html.='$count=$m->where("'.$where.'")->count();';<br>
$html.='$p = new Page ( $count, '.$pagesize.' );';<br>
//如果使用了分页,num将不起作用<br>
$html.='$ret=$m->field("'.$field.'")->where("'.$where.'")->limit($p->firstRow.",".$p->listRows)->order("'.$order.'")->select();';<br>
$html.='$cutInfo ="<div> ". $p->show ()."</div>";'; <br>
}<br>
//如果没有使用分页,并且没有 query<br>
if(!$page && !$query){ <br>
//有缓存<br>
if($cache!=false){<br>
//包含缓存判断<br>
$html.='$cache_key="key_".md5($m->field("'.$field.'")->where("'.$where.'")->order("'.$order.'")->limit("'.$num.'")->select(false));';<br>
$html.='if(!$ret=S($cache_key)){ $ret=$m->field("'.$field.'")->where("'.$where.'")->order("'.$order.'")->limit("'.$num.'")->select(); S($cache_key,$ret,'.$cache.'); }';<br>
}else{<br>
//没有缓存<br>
$html.='$ret=$m->field("'.$field.'")->where("'.$where.'")->order("'.$order.'")->limit("'.$num.'")->select();';<br>
}<br>
<br>
} <br>
if($debug!=false){<br>
$html.='dump($ret);dump($m->getLastSql());';<br>
}<br>
$html.='foreach($ret as $key=>$'.$id.'): ?>';<br>
$html.=$this->tpl->parse($content); <br>
$html.='<?php endforeach; ?>'; <br>
if($page) $html.='<?php echo $cutInfo;?>'; <br>
return $html;<br>
<br>
}</foolist>
这个标签任何版本都通用,(果然很万能),好了现在说说怎么使用
获得文章状态为1的文章列表:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
哎就这么简单,默认id就是为d,如果你要定义就要这样使用,<foolist><br>
<li><a>{$vo.title}</a></li>
<br>
</foolist>
还有如果你要使用:<foolist><br>
<li><a>{$vo.title}</a></li>
<br>
</foolist>
就会报错,没错在任何CX标签中你不能使用=,大于号,小于号,
这个呢官方有介绍,也可查看CX父类的定义:
\Lib\Template\TagLib.class.php protected $comparison = array(' nheq '=>' !== ',' heq '=>' === ',' neq '=>' != ',' eq '=>' == ',' egt '=>' >= ',' gt '=>' > ',' elt '=>' ' 而,mysql使用的=和 ,请使用 sqleq 和 noteq 代替
好了换个吧,如果想指定字段,排序就这样:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
现在是否明白了,只要你回使用model,就会使用介个了。
限制查询数量请使用num,比如只输出10条数据:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
好了下面换点口味。
万能标签是能分页的,你可以这样使用:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
page默认是false,打开之后定义pagesize就好了,分页的内容使用的就是官方的page类,样式自己再调整下就ok了。
foolist当然支持query实现更复杂的查询:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
不过此时的where,num,order,page,field,cache参数将无法使用。
没有在action定义数据来源,foolist也是能实现缓存的,比如对目录查询缓存1小时:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
cache默认是关闭的,想开启缓存直接定义cache为你想缓存的时间即可。
debug的玩法:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
如果你想知道foolist到底有什么数据,请开启debug参数,
此时会dump数据集,和getLastSql() 。
下面说说如何传递$_GET,如果你想或的当前目录下的所有文章,假如$_GET['id']就是目录的id,如此就可以这样使用:<foolist><br>
<li><a>{$d.title}</a></li>
<br>
</foolist>
//====================
foolist使用的model都是通过D实现的,所以想实现更复杂的数据模型,请自己定义自己的model类即可。
如果在数据输出之前想实现更多的业务逻辑,就使用官方的volist,这也是区别所在。
假如你开发了cms,前台的所有风格模板只要使用一个标签就能搞定,方便不,
方便面。。。。。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

WebStorm Mac version
Useful JavaScript development tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.