当前位置: 代码迷 >> PHP >> thinkphp批改及编写标签库,编辑器的使用
  详细解决方案

thinkphp批改及编写标签库,编辑器的使用

热度:71   发布时间:2016-04-28 17:12:49.0
thinkphp修改及编写标签库,编辑器的使用
在view目录下创建Index_aaa.html
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta charset="UTF-8">
  5. <title>select</title>
  6. </head>
  7. <body>
  8. <tagLib name="html"/>
  9. <html:select options="address" selected="sh" values="address"/>
  10. </body>
  11. </html>
在IndexController.class.php里面编写函数
  1. public function aaa(){
  2. $this->assign("address",["sh"=> "上海","天津","北京","郑州"]);
  3. $this->display();
  4. }

修改此文件可以编写标签库

把输出的几项全部改为val即可解决values='0'
的问题,让values的值等于option的值

编写新的标签
      'ms'=>array('attr'=>'id,name,options,selected','close'=>0)  
<html:ms id="aa" name="uu" options="address" selected="北京"/><br> 
修改后的代码selected的值可以随便写即可
 
  1. public function _ms($tag) {
  2. $name = $tag['name'];
  3. $options = $tag['options'];
  4. $id = $tag['id'];
  5. $selected = $tag['selected'];
  6. $parseStr = '<select id="'.$id.'" name="'.$name.'" >';
  7. $parseStr .='<?php foreach($'.$options.' as $val) { ?>';
  8. $parseStr .='<?php if("'.$selected.'"==$val) { ?>';
  9. $parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
  10. $parseStr .= '<?php } else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
  11. $parseStr .= '<?php } ?>';
  12. $parseStr .= '<?php } ?>';
  13. $parseStr .= '</select>';
  14. return $parseStr;
  15. }
可以根据分配的值来确定selected
  1. public function _ms($tag) {
  2. $name = $tag['name'];
  3. $options = $tag['options'];
  4. $id = $tag['id'];
  5. $selected = $tag['selected'];
  6. $parseStr = '<select id="'.$id.'" name="'.$name.'" >';
  7. $parseStr .='<?php foreach($'.$options.' as $val) { ?>';
  8. /* $parseStr .='<?php if("'.$selected.'"==$val) { ?>';*///selected的值可以随便写
  9. $parseStr .='<?php if($'.$selected.'==$val) { ?>';//值可以先分配再写
  10. $parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
  11. $parseStr .= '<?php } else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
  12. $parseStr .= '<?php } ?>';
  13. $parseStr .= '<?php } ?>';
  14. $parseStr .= '</select>';
  15. return $parseStr;
  16. }
  1. public function aaa(){
  2. $this->assign("address",["上海","天津","北京","郑州"]);
  3. $this->assign("sh","天津");
  4. $this->display();
  5. }
  1. <tagLib name="html"/>
  2. <html:ms id="aa" name="uu" options="address" selected="sh"/><br>
用框架本身带的也可以实现

把红线处的$key修改为$val用分配变量的方式也可以实现selected,系统自带的稍加修改,但是值不可以随便写在selected后
  1. public function _select($tag) {
  2. $name = $tag['name'];
  3. $options = $tag['options'];
  4. $values = $tag['values'];
  5. $output = $tag['output'];
  6. $multiple = $tag['multiple'];
  7. $id = $tag['id'];
  8. $size = $tag['size'];
  9. $first = $tag['first'];
  10. $selected = $tag['selected'];
  11. $style = $tag['style'];
  12. $ondblclick = $tag['dblclick'];
  13. $onchange = $tag['change'];
  14. if(!empty($multiple)) {
  15. $parseStr = '<select id="'.$id.'" name="'.$name.'" ondblclick="'.$ondblclick.'" onchange="'.$onchange.'" multiple="multiple" class="'.$style.'" size="'.$size.'" >';
  16. }else {
  17. $parseStr = '<select id="'.$id.'" name="'.$name.'" onchange="'.$onchange.'" ondblclick="'.$ondblclick.'" class="'.$style.'" >';
  18. }
  19. if(!empty($first)) {
  20. $parseStr .= '<option value="" >'.$first.'</option>';
  21. }
  22. if(!empty($options)) {
  23. $parseStr .= '<?php foreach($'.$options.' as $key=>$val) { ?>';
  24. if(!empty($selected)) {
  25. $parseStr .= '<?php if(!empty($'.$selected.') && ($'.$selected.' == $val || in_array($key,$'.$selected.'))) { ?>';
  26. $parseStr .= '<option selected="selected" value="<?php echo $val ?>"><?php echo $val ?></option>';
  27. $parseStr .= '<?php }else { ?><option value="<?php echo $val ?>"><?php echo $val ?></option>';
  28. $parseStr .= '<?php } ?>';
  29. }else {
  30. $parseStr .= '<option value="<?php echo $val ?>"><?php echo $val ?></option>';
  31. }
  32. $parseStr .= '<?php } ?>';
  33. }else if(!empty($values)) {
  34. $parseStr .= '<?php for($i=0;$i<count($'.$values.');$i++) { ?>';
  35. if(!empty($selected)) {
  36. $parseStr .= '<?php if(isset($'.$selected.') && ((is_string($'.$selected.') && $'.$selected.' == $'.$values.'[$i]) || (is_array($'.$selected.') && in_array($'.$values.'[$i],$'.$selected.')))) { ?>';
  37. $parseStr .= '<option selected="selected" value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
  38. $parseStr .= '<?php }else { ?><option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
  39. $parseStr .= '<?php } ?>';
  40. }else {
  41. $parseStr .= '<option value="<?php echo $'.$values.'[$i] ?>"><?php echo $'.$output.'[$i] ?></option>';
  42. }
  43. $parseStr .= '<?php } ?>';
  44. }
  45. $parseStr .= '</select>';
  46. return $parseStr;
  47. }
引入ueditor放在js里面修改ueditor.config.js为如下的代码
  1. window.UEDITOR_HOME_URL = "/Public/js/ueditor/";


thinkphp里面放百度编辑器
  1. $parseStr = '<script id="container" name="content" type="text/plain">这里写你的初始化内容</script><script type="text/javascript" src="__ROOT__/Public/js/ueditor/ueditor.config.js"></script><script type="text/javascript" src="__ROOT__/Public/js/ueditor/ueditor.all.js"></script><script type="text/javascript"> var ue = UE.getEditor("container",{emotionLocalization:true,lang:"zh-cn",initialFrameWidth:"80%",initialFrameHeight:320,textarea:"content",initialContent:"欢迎留言!", autoClearinitialContent:true}); </script>';
然后在Index_aaa.html 里面编写要显示的代码
  1. <tagLib name="html"/>
  2. <html:editor type="UEDITOR"></html:editor>