GroupInput.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. namespace common\widgets\input;
  3. use yii\helpers\Html;
  4. use yii\widgets\InputWidget;
  5. /**
  6. * Class GroupInput
  7. * @package common\widgets\input
  8. * @author jianyan74 <751393839@qq.com>
  9. */
  10. class GroupInput extends InputWidget
  11. {
  12. /**
  13. * @var string
  14. */
  15. public $prepend = '';
  16. /**
  17. * @var string
  18. */
  19. public $append = '';
  20. /**
  21. * @var array
  22. */
  23. public $options = [];
  24. /**
  25. * @return string|void
  26. */
  27. public function run()
  28. {
  29. $value = $this->hasModel() ? Html::getAttributeValue($this->model, $this->attribute) : $this->value;
  30. $name = $this->hasModel() ? Html::getInputName($this->model, $this->attribute) : $this->name;
  31. if (empty($this->options['id'])) {
  32. $this->options['id'] = $this->hasModel() ? Html::getInputId($this->model, $this->attribute) : md5($name);
  33. }
  34. return $this->render('group', [
  35. 'value' => $value,
  36. 'name' => $name,
  37. 'options' => $this->options,
  38. 'prepend' => $this->prepend,
  39. 'append' => $this->append,
  40. ]);
  41. }
  42. }
粤ICP备19079148号