BootstrapUI\View\Helper\HtmlHelper::label PHP Метод

label() публичный Метод

Returns Bootstrap label markup. By default, uses .
public label ( string $text, array $options = [] ) : string
$text string Text to show in label.
$options array Additional HTML attributes.
Результат string HTML icon markup.
    public function label($text, $options = [])
    {
        if (is_string($options)) {
            $options = ['type' => $options];
        }
        $options += ['tag' => 'span', 'type' => 'default'];
        $classes = ['label', 'label-' . $options['type']];
        $tag = $options['tag'];
        unset($options['tag'], $options['type']);
        return $this->tag($tag, $text, $this->injectClasses($classes, $options));
    }

Usage Example

Пример #1
0
 public function testLabel()
 {
     $result = $this->Html->label('foo');
     $expected = ['span' => ['class' => 'label label-default'], 'foo', '/span'];
     $this->assertHtml($expected, $result);
     $result = $this->Html->label('foo', 'warning');
     $expected = ['span' => ['class' => 'label label-warning'], 'foo', '/span'];
     $this->assertHtml($expected, $result);
     $result = $this->Html->label('foo', ['type' => 'custom']);
     $expected = ['span' => ['class' => 'label label-custom'], 'foo', '/span'];
     $this->assertHtml($expected, $result);
 }