当前位置: 首页>>代码示例>>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;未经允许,请勿转载。