Button.php 1.23 KB
Newer Older
1 2 3 4 5 6 7 8 9
<?php
/**
 * @link http://www.yiiframework.com/
 * @copyright Copyright (c) 2008 Yii Software LLC
 * @license http://www.yiiframework.com/license/
 */

namespace yii\bootstrap;

resurtm committed
10
use yii\helpers\Html;
11 12

/**
13
 * Button renders a bootstrap button.
14 15 16 17
 *
 * For example,
 *
 * ```php
Alexander Makarov committed
18
 * echo Button::widget([
19
 *     'label' => 'Action',
Alexander Makarov committed
20 21
 *     'options' => ['class' => 'btn-lg'],
 * ]);
22
 * ```
MarsuBoss committed
23
 * @see http://getbootstrap.com/javascript/#buttons
24 25 26 27 28
 * @author Antonio Ramirez <amigo.cobos@gmail.com>
 * @since 2.0
 */
class Button extends Widget
{
Qiang Xue committed
29 30 31 32 33 34 35 36 37 38 39 40
	/**
	 * @var string the tag to use to render the button
	 */
	public $tagName = 'button';
	/**
	 * @var string the button label
	 */
	public $label = 'Button';
	/**
	 * @var boolean whether the label should be HTML-encoded.
	 */
	public $encodeLabel = true;
41 42


Qiang Xue committed
43 44 45 46 47 48 49 50
	/**
	 * Initializes the widget.
	 * If you override this method, make sure you call the parent implementation first.
	 */
	public function init()
	{
		parent::init();
		$this->clientOptions = false;
51
		Html::addCssClass($this->options, 'btn');
Qiang Xue committed
52
	}
53

Qiang Xue committed
54 55 56 57 58 59 60 61 62
	/**
	 * Renders the widget.
	 */
	public function run()
	{
		echo Html::tag($this->tagName, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options);
		$this->registerPlugin('button');
	}
}