Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

63 lines
1.3KB

  1. <?php
  2. /**
  3. * @link http://www.yiiframework.com/
  4. * @copyright Copyright (c) 2008 Yii Software LLC
  5. * @license http://www.yiiframework.com/license/
  6. */
  7. namespace yii\bootstrap;
  8. use yii\helpers\Html;
  9. /**
  10. * Button renders a bootstrap button.
  11. *
  12. * For example,
  13. *
  14. * ```php
  15. * echo Button::widget([
  16. * 'label' => 'Action',
  17. * 'options' => ['class' => 'btn-lg'],
  18. * ]);
  19. * ```
  20. * @see http://getbootstrap.com/javascript/#buttons
  21. * @author Antonio Ramirez <amigo.cobos@gmail.com>
  22. * @since 2.0
  23. */
  24. class Button extends Widget
  25. {
  26. /**
  27. * @var string the tag to use to render the button
  28. */
  29. public $tagName = 'button';
  30. /**
  31. * @var string the button label
  32. */
  33. public $label = 'Button';
  34. /**
  35. * @var boolean whether the label should be HTML-encoded.
  36. */
  37. public $encodeLabel = true;
  38. /**
  39. * Initializes the widget.
  40. * If you override this method, make sure you call the parent implementation first.
  41. */
  42. public function init()
  43. {
  44. parent::init();
  45. $this->clientOptions = false;
  46. Html::addCssClass($this->options, 'btn');
  47. }
  48. /**
  49. * Renders the widget.
  50. */
  51. public function run()
  52. {
  53. $this->registerPlugin('button');
  54. return Html::tag($this->tagName, $this->encodeLabel ? Html::encode($this->label) : $this->label, $this->options);
  55. }
  56. }