CopyInput.php 1013 B

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