在destoon中模块的自定义字段存储在destonn_fields这个表中
自定义字段的前台显示使用的是fields_html这个函数在fields.func.php文件中,这个函数的定义如下,
function fields_html($left = '<td class="tl">', $right = '<td>', $values = array(), $fd = array()) { extract($GLOBALS, EXTR_SKIP); if($fd) $FD = $fd; $html = ''; foreach($FD as $k=>$v) { if(!$v['display']) continue; if(!defined('DT_ADMIN') && !$v['front']) continue; $html .= fields_show($k, $left, $right, $values, $fd); } return $html; }
这个函数不是使用$left与right这两个变量中包含的html包住我们自定义的字段,这样就显示非常的不和谐,很不好自定义界面,
这个函数中使用的了一个$FD的变量,这个变量是一个全局变量,在用户中心显示编辑界面时,变量的初始公是在my.inc.php中
if (in_array($action, array('add', 'edit'))) { $FD = cache_read('fields-' . substr($table, strlen($DT_PRE)) . '.php'); if ($FD) require DT_ROOT . '/include/fields.func.php'; isset($post_fields) or $post_fields = array(); $CP = $MOD['cat_property']; if ($CP) require DT_ROOT . '/include/property.func.php'; isset($post_ppt) or $post_ppt = array(); }
<?php defined('IN_DESTOON') or exit('Access Denied'); return array( 19 => array('itemid' => '19', 'tb' => 'dingzhi_40', 'name' => 'qidian', 'title' => '起点', 'note' => '', 'type' => 'int', 'length' => '10', 'html' => 'area', 'default_value' => '', 'option_value' => '', 'width' => '120', 'height' => '90', 'input_limit' => '', 'addition' => '', 'display' => '1', 'front' => '1', 'listorder' => '0',), 20 => array('itemid' => '20', 'tb' => 'dingzhi_40', 'name' => 'zhongdian', 'title' => '终点', 'note' => '', 'type' => 'int', 'length' => '10', 'html' => 'area', 'default_value' => '', 'option_value' => '', 'width' => '120', 'height' => '90', 'input_limit' => '', 'addition' => '', 'display' => '1', 'front' => '1', 'listorder' => '0',), 21 => array('itemid' => '21', 'tb' => 'dingzhi_40', 'name' => 'shuojihao', 'title' => '手机号', 'note' => '', 'type' => 'varchar', 'length' => '15', 'html' => 'text', 'default_value' => '', 'option_value' => '', 'width' => '120', 'height' => '90', 'input_limit' => '', 'addition' => 'size="30"', 'display' => '1', 'front' => '1', 'listorder' => '0',), 22 => array('itemid' => '22', 'tb' => 'dingzhi_40', 'name' => 'shixiao', 'title' => '时效', 'note' => '', 'type' => 'varchar', 'length' => '255', 'html' => 'radio', 'default_value' => '', 'option_value' => '1|1天内*2|2天内*3|3天内*4|4天内*5|5天内*6|6天内*7|7天内*', 'width' => '120', 'height' => '90', 'input_limit' => '', 'addition' => '', 'display' => '1', 'front' => '1', 'listorder' => '0',),); ?>
个人觉得如果要修改某个字段的相关特性时,只需要传入特定属性就可以了,因此我对函数做了一点改变,因为我只需要改变title就可以,所以没有对这个函数做太大的改动
{php $mycust=array("qidian"=>"发车起点:");}
{if $FD}{fields_html3('<li><p>--name--:</p><span>--control--</span></li>',$item, $mycust)}{/if}
function fields_html3($template, $values = array(), $mycust = array()) { extract($GLOBALS, EXTR_SKIP); // if($fd) $FD = $fd;这里的本意是用我们自定义的字段来替换从缓存中读取的字段,但是这样的就有点麻烦, // print_r($FD); $html = ''; foreach ($FD as $k => &$v) { if (!$v['display']) continue; if (!defined('DT_ADMIN') && !$v['front']) continue; $v["temphtml"] = fields_show2($k, $values ); $title = $v["title"]; if(isset($mycust[$v["name"]])) $title = $mycust[$v['name']]; $temp = str_replace("--name--", $title,$template); $temp = str_replace("--control--", $v["temphtml"],$temp); $html.=$temp."\r\n"; } return $html; }