TbHtml::icon PHP Method

icon() public static method

Generates an icon.
public static icon ( string $icon, array $htmlOptions = [], string $tagName = 'span' ) : string
$icon string the icon type.
$htmlOptions array additional HTML attributes.
$tagName string the icon HTML tag.
return string the generated icon.
    public static function icon($icon, $htmlOptions = array(), $tagName = 'span')
    {
        if (is_string($icon)) {
            if (strpos($icon, 'glyphicon-') === false) {
                $icon = 'glyphicon-' . implode(' glyphicon-', explode(' ', $icon));
            }
            self::addCssClass(array('glyphicon', $icon), $htmlOptions);
            $color = TbArray::popValue('color', $htmlOptions);
            if (!empty($color) && $color === self::ICON_COLOR_WHITE) {
                self::addCssClass("glyphicon-white", $htmlOptions);
            }
            return self::openTag($tagName, $htmlOptions) . parent::closeTag($tagName);
            // tag won't work in this case
        }
        return '';
    }

Usage Example

Example #1
0
    /**
     * Renders the input file field
     */
    public function renderField()
    {
        list($name, $id) = $this->resolveNameID();
        TbArray::defaultValue('id', $id, $this->htmlOptions);
        TbArray::defaultValue('name', $name, $this->htmlOptions);
        echo CHtml::openTag('div', $this->htmlOptions);
        echo CHtml::openTag('div', array('class' => 'input-prepend bfh-timepicker-toggle', 'data-toggle' => 'bfh-timepicker'));
        echo CHtml::tag('span', array('class' => 'add-on'), TbHtml::icon(TbHtml::ICON_TIME));
        if ($this->hasModel()) {
            echo CHtml::activeTextField($this->model, $this->attribute, $this->inputOptions);
        } else {
            echo CHtml::textField($name, $this->value, $this->inputOptions);
        }
        echo CHtml::closeTag('div');
        echo '<div class="bfh-timepicker-popover">
				<table class="table">
				<tbody>
					<tr>
						<td class="hour">
						<a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
						<input type="text" class="input-mini" readonly><br>
						<a class="previous" href="#"><i class="icon-chevron-down"></i></a>
						</td>
						<td class="separator">:</td>
						<td class="minute">
						<a class="next" href="#"><i class="icon-chevron-up"></i></a><br>
						<input type="text" class="input-mini" readonly><br>
						<a class="previous" href="#"><i class="icon-chevron-down"></i></a>
						</td>
					</tr>
				</tbody>
				</table>
			</div>';
        echo CHtml::closeTag('div');
    }
All Usage Examples Of TbHtml::icon
TbHtml