Home  >  Article  >  php教程  >  Tinkphp彩色标签Tags的实现方法

Tinkphp彩色标签Tags的实现方法

PHP中文网
PHP中文网Original
2016-05-25 17:09:041148browse


我们浏览网页时经常看到眩目的彩色标签,而且每刷新一下浏览器,都会更新为不同的颜,是不是很“惊艳”?现在来看一下它在Thinkphp上的现实方法。
 
项目函数库的位置:项目\Common\common.php
项目函数库加入以下处理函数
 
 
1 function rcolor() {   
 
2 $rand = rand(0,255);//随机获取0--255的数字   
 
3 return sprintf("%02X","$rand");//输出十六进制的两个大写字母   
 
4 }   
 
5 function rand_color(){   
 
6     return '#'.rcolor().rcolor().rcolor();//六个字母   
 
7 } 
在控制器加入获取标签列表的方法
 
1 //标签控制器查询标签表以获取标签列表   
 
2     function Tags($Module) {   
 
3         $Tag = M('Tag');   
 
4         $map['module']= $Module;   
 
5         $Tagslist = $Tag->where($map)->field('id,name,count')->order('count desc')->limit('0,25')->select();   
 
6         $this->assign('tags', $Tagslist);   
 
7         $this->display();   
 
8      
 
9 } 
把标签列表输出在模板上
 
 
1 <volist id="vo" name="tags" >   
 
2  <li><a href="{:U(&#39;/web&#39;,&#39;tag=&#39;.$vo[&#39;name&#39;]|urlencode)}"><span style="font-size:{color:{$vo.id|rand_color}">  {$vo.name}[{$vo.count}]</span></a></li>   
 
3   </volist> 
说明:{$vo.id|rand_color}为调用项目函数库的“ rand_color()”方法。

                   

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn