Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

89 lines
3.2KB

  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\ArrayHelper;
  9. /**
  10. * BaseHtml provides concrete implementation for [[Html]].
  11. *
  12. * Do not use BaseHtml. Use [[Html]] instead.
  13. *
  14. * @author Paul Klimov <klimov.paul@gmail.com>
  15. * @since 2.0.5
  16. */
  17. class BaseHtml extends \yii\helpers\Html
  18. {
  19. /**
  20. * Composes icon HTML for bootstrap Glyphicons.
  21. * @param string $name icon short name, for example: 'star'
  22. * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  23. * the attributes of the resulting tag. There are also a special options:
  24. *
  25. * - tag: string, tag to be rendered, by default 'span' is used.
  26. * - prefix: string, prefix which should be used to compose tag class, by default 'glyphicon glyphicon-' is used.
  27. *
  28. * @return string icon HTML.
  29. * @see http://getbootstrap.com/components/#glyphicons
  30. */
  31. public static function icon($name, $options = [])
  32. {
  33. $tag = ArrayHelper::remove($options, 'tag', 'span');
  34. $classPrefix = ArrayHelper::remove($options, 'prefix', 'glyphicon glyphicon-');
  35. static::addCssClass($options, $classPrefix . $name);
  36. return static::tag($tag, '', $options);
  37. }
  38. /**
  39. * Renders Bootstrap static form control.
  40. *
  41. * By default value will be HTML-encoded using [[encode()]], you may control this behavior
  42. * via 'encode' option.
  43. * @param string $value static control value.
  44. * @param array $options the tag options in terms of name-value pairs. These will be rendered as
  45. * the attributes of the resulting tag. There are also a special options:
  46. *
  47. * - encode: boolean, whether value should be HTML-encoded or not.
  48. *
  49. * @return string generated HTML
  50. * @see http://getbootstrap.com/css/#forms-controls-static
  51. */
  52. public static function staticControl($value, $options = [])
  53. {
  54. static::addCssClass($options, 'form-control-static');
  55. $value = (string) $value;
  56. if (isset($options['encode'])) {
  57. $encode = $options['encode'];
  58. unset($options['encode']);
  59. } else {
  60. $encode = true;
  61. }
  62. return static::tag('p', $encode ? static::encode($value) : $value, $options);
  63. }
  64. /**
  65. * Generates a Bootstrap static form control for the given model attribute.
  66. * @param \yii\base\Model $model the model object.
  67. * @param string $attribute the attribute name or expression. See [[getAttributeName()]] for the format
  68. * about attribute expression.
  69. * @param array $options the tag options in terms of name-value pairs. See [[staticControl()]] for details.
  70. * @return string generated HTML
  71. * @see staticControl()
  72. */
  73. public static function activeStaticControl($model, $attribute, $options = [])
  74. {
  75. if (isset($options['value'])) {
  76. $value = $options['value'];
  77. unset($options['value']);
  78. } else {
  79. $value = static::getAttributeValue($model, $attribute);
  80. }
  81. return static::staticControl($value, $options);
  82. }
  83. }