在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;
}