zoukankan      html  css  js  c++  java
  • ThinkPHP 自定义标签测试 冰糖

    测试功能:根据source(二维数组或文本[1,男|0,女])生成单选按钮组,
    text:显示值 对于二维数组

    val:取值 对于二维数组

    文本:逗号前为值,后为显示值

    <?php
    
    /**
     +-----------------------------
     * @desc ThinkPHP Fcb自定义标签
     +-----------------------------
     * @author 710
     +-----------------------------
     * @date 2011-12-14
     +-----------------------------
     */
    import("TagLib");
    class TagLibFcb extends TagLib{
    	
    	protected $tags = array(
    	  'radiolist'=>array('attr'=>'name,source,type,text,val,checked,style,class','close'=>0,'level'=>3,'alias'=>'rt,rl'),
    	);
    	
    	/**
    	 +-------------------------------
    	 * @desc  fcb:radiolist 解析
    	 * @param string $type=>数据源类型
    	 * list:数组源,text:文本源(如:1,男|2,女)
    	 +-------------------------------
    	 */
    	public function _radiolist($attr,$content,$type='list'){
    		$tag = $this->parseXmlAttr($attr,'radiolist');
    		$type = empty($tag['type']) ? $type : $tag['type'];
    		$source = $tag['source'];
    		$name = isset($tag['name']) ? 'radio'.date('is') : $tag['name'];
    		$text = empty($tag['text']) ? 'text' : $tag['text'];
    		$val = empty($tag['val']) ? 'id' : $tag['val'];
    		$style = empty($tag['style']) ? '' : 'style="'. $tag['style'].'"';
    		$class= empty($tag['class']) ? '' : 'class="'. $tag['class'].'"';
    		$checked = isset($tag['checked']) ? $tag['checked'] : '';
    		$result='';
    		if($type=='list'){
    			$result.='<?php foreach($'.$source.' as $key=>$val): ?>';
    			$result.='<input type="radio" <?php if($val['.$val.']=="'.$checked.'"): echo "checked=\"checked\"";endif ?>   '.$class.' '.$style.' name="'.$name.'" value="<?php echo $val['.$val.'] ?>" /><?php echo $val['.$text.'] ?>';
    			$result.='<?php endforeach ?>';
    		}elseif($type=='text'){
    			$list = explode("|",$source);
    			foreach($list as $key=>$val){
    				$item = explode(",",$val);
    				$result .= '<input type="radio" '.($item[0]==$checked?"checked=\"checked\"":"").' value="'.$item[0].'" name="'.$name.'" '.$class.' '.$style.' />'.$item[1];
    			}
    		}
    		return $result;
    	}
    	
    	/**
    	 +------------------------------
    	 * radiolist 别名 => 数据源为文本
    	 * <fcb:rt source="1,男|2,女" />
    	 * 逗号前为取得值,后为显示值
    	 +------------------------------
    	 */
    	public function _rt($attr,$content){
    		return $this->_radiolist($attr, $content,'text');
    	}
    	
    	/**
    	 +-------------------------------
    	 * radiolist 别名=> 数据源为数组
    	 * <fcb:rl source="list" text="name" val="id" />
    	 * text:显示值,val:取值
    	 +-------------------------------
    	 */
    	public function _rl($attr,$content){
    		return $this->_radiolist($attr, $content,'list');
    	}
    	
    }
    ?>
    
  • 相关阅读:
    bootstrap-15
    sqlserver 根据指定值截取字符串
    idea针对有外联jar包的项目如何编译成可运行的jar包
    中控考勤机超级管理员密码算法
    sql server 取多条数据的最大值
    bat 脚本定时删除备份文件
    Spyder汉化教程
    君荣一卡通软件mysql转sqlserver 教程
    office2016专业增强版激活密匙 (shell激活版)
    sql 获取当前时间的前一天,不加时分秒
  • 原文地址:https://www.cnblogs.com/hxtgirq710/p/tplib.html
Copyright © 2011-2022 走看看