當前位置: 首頁>>代碼示例>>PHP>>正文


PHP DataUtil::formatForDisplayHtml方法代碼示例

本文整理匯總了PHP中DataUtil::formatForDisplayHtml方法的典型用法代碼示例。如果您正苦於以下問題:PHP DataUtil::formatForDisplayHtml方法的具體用法?PHP DataUtil::formatForDisplayHtml怎麽用?PHP DataUtil::formatForDisplayHtml使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在DataUtil的用法示例。


在下文中一共展示了DataUtil::formatForDisplayHtml方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: getSelector_Categories

 /**
  * Return the HTML selector code for the given category hierarchy.
  *
  * @param array        $cats             The category hierarchy to generate a HTML selector for.
  * @param string       $field            The field value to return (optional) (default='id').
  * @param string|array $selectedValue    The selected category (optional) (default=0).
  * @param string       $name             The name of the selector field to generate (optional) (default='category[parent_id]').
  * @param intiger      $defaultValue     The default value to present to the user (optional) (default=0).
  * @param string       $defaultText      The default text to present to the user (optional) (default='').
  * @param intiger      $allValue         The value to assign to the "all" option (optional) (default=0).
  * @param string       $allText          The text to assign to the "all" option (optional) (default='').
  * @param boolean      $submit           Whether or not to submit the form upon change (optional) (default=false).
  * @param boolean      $displayPath      If false, the path is simulated, if true, the full path is shown (optional) (default=false).
  * @param boolean      $doReplaceRootCat Whether or not to replace the root category with a localized string (optional) (default=true).
  * @param intiger      $multipleSize     If > 1, a multiple selector box is built, otherwise a normal/single selector box is build (optional) (default=1).
  * @param boolean      $fieldIsAttribute True if the field is attribute (optional) (default=false).
  *
  * @return The HTML selector code for the given category hierarchy
  */
 public static function getSelector_Categories($cats, $field = 'id', $selectedValue = '0', $name = 'category[parent_id]', $defaultValue = 0, $defaultText = '', $allValue = 0, $allText = '', $submit = false, $displayPath = false, $doReplaceRootCat = true, $multipleSize = 1, $fieldIsAttribute = false)
 {
     $line = '---------------------------------------------------------------------';
     if ($multipleSize > 1 && strpos($name, '[]') === false) {
         $name .= '[]';
     }
     if (!is_array($selectedValue)) {
         $selectedValue = array((string) $selectedValue);
     }
     $id = strtr($name, '[]', '__');
     $multiple = $multipleSize > 1 ? ' multiple="multiple"' : '';
     $multipleSize = $multipleSize > 1 ? " size=\"{$multipleSize}\"" : '';
     $submit = $submit ? ' onchange="this.form.submit();"' : '';
     $lang = ZLanguage::getLanguageCode();
     $html = "<select name=\"{$name}\" id=\"{$id}\"{$multipleSize}{$multiple}{$submit}>";
     if (!empty($defaultText)) {
         $sel = in_array((string) $defaultValue, $selectedValue) ? ' selected="selected"' : '';
         $html .= "<option value=\"{$defaultValue}\"{$sel}>{$defaultText}</option>";
     }
     if ($allText) {
         $sel = in_array((string) $allValue, $selectedValue) ? ' selected="selected"' : '';
         $html .= "<option value=\"{$allValue}\"{$sel}>{$allText}</option>";
     }
     $count = 0;
     if (!isset($cats) || empty($cats)) {
         $cats = array();
     }
     foreach ($cats as $cat) {
         if ($fieldIsAttribute) {
             $sel = in_array((string) $cat['__ATTRIBUTES__'][$field], $selectedValue) ? ' selected="selected"' : '';
         } else {
             $sel = in_array((string) $cat[$field], $selectedValue) ? ' selected="selected"' : '';
         }
         if ($displayPath) {
             if ($fieldIsAttribute) {
                 $v = $cat['__ATTRIBUTES__'][$field];
                 $html .= "<option value=\"{$v}\"{$sel}>{$cat['path']}</option>";
             } else {
                 $html .= "<option value=\"{$cat[$field]}\"{$sel}>{$cat['path']}</option>";
             }
         } else {
             $cslash = StringUtil::countInstances(isset($cat['ipath_relative']) ? $cat['ipath_relative'] : $cat['ipath'], '/');
             $indent = '';
             if ($cslash > 0) {
                 $indent = substr($line, 0, $cslash * 2);
             }
             $indent = '|' . $indent;
             //if ($count) {
             //    $indent = '|' . $indent;
             //} else {
             //    $indent = '&nbsp;' . $indent;
             //}
             if (isset($cat['display_name'][$lang]) && !empty($cat['display_name'][$lang])) {
                 $catName = $cat['display_name'][$lang];
             } else {
                 $catName = $cat['name'];
             }
             if ($fieldIsAttribute) {
                 $v = $cat['__ATTRIBUTES__'][$field];
                 $html .= "<option value=\"{$v}\"{$sel}>{$indent} " . DataUtil::formatForDisplayHtml($catName) . "</option>";
             } else {
                 $html .= "<option value=\"{$cat[$field]}\"{$sel}>{$indent} " . DataUtil::formatForDisplayHtml($catName) . "</option>";
             }
         }
         $count++;
     }
     $html .= '</select>';
     if ($doReplaceRootCat) {
         $html = str_replace('__SYSTEM__', __('Root category'), $html);
     }
     return $html;
 }
開發者ID:projectesIF,項目名稱:Sirius,代碼行數:91,代碼來源:CategoryUtil.php


注:本文中的DataUtil::formatForDisplayHtml方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。