SecretKeyInput.php 956 B

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