foolist万能标签
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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Learn about Python programming with introductory code examples Python is an easy-to-learn, yet powerful programming language. For beginners, it is very important to understand the introductory code examples of Python programming. This article will provide you with some concrete code examples to help you get started quickly. Print HelloWorldprint("HelloWorld") This is the simplest code example in Python. The print() function is used to output the specified content

"Go Language Programming Examples: Code Examples in Web Development" With the rapid development of the Internet, Web development has become an indispensable part of various industries. As a programming language with powerful functions and superior performance, Go language is increasingly favored by developers in web development. This article will introduce how to use Go language for Web development through specific code examples, so that readers can better understand and use Go language to build their own Web applications. 1. Simple HTTP Server First, let’s start with a

The simplest code example of Java bubble sort Bubble sort is a common sorting algorithm. Its basic idea is to gradually adjust the sequence to be sorted into an ordered sequence through the comparison and exchange of adjacent elements. Here is a simple Java code example that demonstrates how to implement bubble sort: publicclassBubbleSort{publicstaticvoidbubbleSort(int[]arr){int

PHP variables store values during program runtime and are crucial for building dynamic and interactive WEB applications. This article takes an in-depth look at PHP variables and shows them in action with 10 real-life examples. 1. Store user input $username=$_POST["username"];$passWord=$_POST["password"]; This example extracts the username and password from the form submission and stores them in variables for further processing. 2. Set the configuration value $database_host="localhost";$database_username="username";$database_pa

Title: From Beginner to Mastery: Code Implementation of Commonly Used Data Structures in Go Language Data structures play a vital role in programming and are the basis of programming. In the Go language, there are many commonly used data structures, and mastering the implementation of these data structures is crucial to becoming a good programmer. This article will introduce the commonly used data structures in the Go language and give corresponding code examples to help readers from getting started to becoming proficient in these data structures. 1. Array Array is a basic data structure, a group of the same type

Huawei Cloud Edge Computing Interconnection Guide: Java Code Samples to Quickly Implement Interfaces With the rapid development of IoT technology and the rise of edge computing, more and more enterprises are beginning to pay attention to the application of edge computing. Huawei Cloud provides edge computing services, providing enterprises with highly reliable computing resources and a convenient development environment, making edge computing applications easier to implement. This article will introduce how to quickly implement the Huawei Cloud edge computing interface through Java code. First, we need to prepare the development environment. Make sure you have the Java Development Kit installed (

How to use PHP to write the inventory management function code in the inventory management system. Inventory management is an indispensable part of many enterprises. For companies with multiple warehouses, the inventory management function is particularly important. By properly managing and tracking inventory, companies can allocate inventory between different warehouses, optimize operating costs, and improve collaboration efficiency. This article will introduce how to use PHP to write code for inventory warehouse management functions, and provide you with relevant code examples. 1. Establish the database before starting to write the code for the inventory warehouse management function.

Java Selection Sorting Method Code Writing Guide and Examples Selection sorting is a simple and intuitive sorting algorithm. The idea is to select the smallest (or largest) element from the unsorted elements each time and exchange it until all elements are sorted. This article will provide a code writing guide for selection sorting, and attach specific Java sample code. Algorithm Principle The basic principle of selection sort is to divide the array to be sorted into two parts, sorted and unsorted. Each time, the smallest (or largest) element is selected from the unsorted part and placed at the end of the sorted part. Repeat the above
