destoon中自定義欄位的前臺顯示,及修改相關屬性

大東瓜123發表於2017-02-07

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

$FD是從快取中讀取的,其中的形式如下,

<?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`,),);
?>

如果我們需要對欄位的顯示名稱進行更改,那麼就需要傳入整個array才能達到目的,個人覺得有點麻煩了

個人覺得如果要修改某個欄位的相關特性時,只需要傳入特定屬性就可以了,因此我對函式做了一點改變,因為我只需要改變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."
";
    }

    return $html;
}


相關文章