本文整理汇总了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 = ' ' . $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;
}