TbHtml::btn PHP Method

btn() public static method

Generates a button.
public static btn ( string $type, string $label, array $htmlOptions = [] ) : string
$type string the button type.
$label string the button label text.
$htmlOptions array additional HTML attributes.
return string the generated button.
    public static function btn($type, $label, $htmlOptions = array())
    {
        self::addCssClass('btn', $htmlOptions);
        $color = TbArray::popValue('color', $htmlOptions, self::BUTTON_COLOR_DEFAULT);
        if (!empty($color)) {
            self::addCssClass('btn-' . $color, $htmlOptions);
        }
        $size = TbArray::popValue('size', $htmlOptions);
        if (!empty($size)) {
            self::addCssClass('btn-' . $size, $htmlOptions);
        }
        if (TbArray::popValue('block', $htmlOptions, false)) {
            self::addCssClass('btn-block', $htmlOptions);
        }
        if (TbArray::popValue('disabled', $htmlOptions, false)) {
            self::addCssClass('disabled', $htmlOptions);
            $htmlOptions['disabled'] = 'disabled';
        }
        $loading = TbArray::popValue('loading', $htmlOptions);
        if (!empty($loading)) {
            $htmlOptions['data-loading-text'] = $loading;
        }
        if (TbArray::popValue('toggle', $htmlOptions, false)) {
            $htmlOptions['data-toggle'] = 'button';
        }
        $icon = TbArray::popValue('icon', $htmlOptions);
        $iconOptions = TbArray::popValue('iconOptions', $htmlOptions, array());
        if (!is_array($type) && strpos($type, 'input') === false) {
            if (!empty($icon)) {
                $label = self::icon($icon, $iconOptions) . ' ' . $label;
            }
            $items = TbArray::popValue('items', $htmlOptions);
        }
        $dropdownOptions = $htmlOptions;
        TbArray::removeValues(array('groupOptions', 'menuOptions', 'dropup'), $htmlOptions);
        self::addSpanClass($htmlOptions);
        // must be called here as parent renders buttons
        self::addPullClass($htmlOptions);
        // must be called here as parent renders buttons
        return isset($items) ? self::btnDropdown($type, $label, $items, $dropdownOptions) : self::createButton($type, $label, $htmlOptions);
    }

Usage Example

 /**
  * Returns this button.
  * @return string the rendering result.
  */
 public function render()
 {
     $attributes = $this->attributes;
     $attributes['name'] = $this->name;
     if (isset(self::$coreTypes[$this->type])) {
         $type = self::$coreTypes[$this->type];
         return TbHtml::btn($type, $this->label, $attributes);
     } else {
         return $this->getParent()->getOwner()->widget($this->type, $attributes, true);
     }
 }
All Usage Examples Of TbHtml::btn
TbHtml