ActiveField.php 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: NODELOG
  5. * Date: 2017/2/11
  6. * Time: 下午9:43
  7. */
  8. namespace backend\widgets;
  9. use yii\helpers\ArrayHelper;
  10. use yii\helpers\Html;
  11. class ActiveField extends \yii\widgets\ActiveField
  12. {
  13. public function staticControl($options = [])
  14. {
  15. $this->adjustLabelFor($options);
  16. $this->parts['{input}'] = Html::activeStaticControl($this->model, $this->attribute, $options);
  17. return $this;
  18. }
  19. public function suffix($suffix = '', $suffixType = 'addon', $size = 300)
  20. {
  21. $size = !empty($size) ? "input-group-{$size} " : '';
  22. $this->template = "{label}\n<div class=\"input-group $size\">{input}\n<div class=\"input-group-" . $suffixType . "\">" . $suffix . "</div></div>\n{hint}\n{error}";
  23. return $this;
  24. }
  25. public function prefix($prefix = '', $prefixType = 'addon', $size = 300)
  26. {
  27. $size = !empty($size) ? "input-group-{$size} " : '';
  28. $this->template = "{label}\n<div class=\"input-group $size\"><div class=\"input-group-" . $prefixType . "\">" . $prefix . "</div>\n{input}</div>\n{hint}\n{error}";
  29. return $this;
  30. }
  31. public function boolean($options = [], $enclosedByLabel = true)
  32. {
  33. if ($enclosedByLabel) {
  34. $this->parts['{input}'] = Html::activeBoolean($this->model, $this->attribute, $options);
  35. $this->parts['{label}'] = '';
  36. } else {
  37. if (isset($options['label']) && !isset($this->parts['{label}'])) {
  38. $this->parts['{label}'] = $options['label'];
  39. if (!empty($options['labelOptions'])) {
  40. $this->labelOptions = $options['labelOptions'];
  41. }
  42. }
  43. unset($options['labelOptions']);
  44. $options['label'] = null;
  45. $this->parts['{input}'] = Html::activeBoolean($this->model, $this->attribute, $options);
  46. }
  47. $this->adjustLabelFor($options);
  48. return $this;
  49. }
  50. /**
  51. * 输入框添加尾巴
  52. * @param string $suffix
  53. * @param string $suffixType
  54. * @return $this
  55. * @author nodelog
  56. */
  57. public function inputSuffix($suffix = '', $suffixType = 'addon')
  58. {
  59. $this->parts['{input}'] = "<div class=\"input-group \">" . $this->parts['{input}'] ."<div class=\"input-group-" . $suffixType . "\">" . $suffix . "</div></div>";
  60. return $this;
  61. }
  62. }