You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

72 lines
2.0 KiB

  1. <?php
  2. /**
  3. * Created by PhpStorm.
  4. * User: wangxj
  5. * Date: 2017/5/27
  6. * Time: 14:19
  7. */
  8. namespace common\components;
  9. use yii\helpers\Html;
  10. use yii\widgets\ActiveField;
  11. class zActiveField extends ActiveField
  12. {
  13. // private $_inputId;
  14. private $_skipLabelFor = false;
  15. public function textInput($options = [])
  16. {
  17. $options = array_merge($this->inputOptions, $options);
  18. $this->adjustLabelFor($options);
  19. $this->parts['{input}'] = Html::activeTextInput($this->model, $this->attribute, $options);
  20. if (isset($options['unit'])) {
  21. if (isset($options['Yii'])) {
  22. $this->parts['{input}'] = '<div class="input-group ' . $options['Yii'] . '" >' . $this->parts['{input}'];
  23. } else {
  24. $this->parts['{input}'] = '<div class="input-group" >' . $this->parts['{input}'];
  25. }
  26. $this->parts['{input}'] .= $options['unit'] . '</div>';
  27. }
  28. return $this;
  29. }
  30. /**
  31. * User: wangxj
  32. *
  33. * 重写textInput框,options['Yii']设置'zzcx',注意第一个参数传 null
  34. *
  35. * @param array $options
  36. * @return ActiveField
  37. */
  38. public function label($label = null, $options = [])
  39. {
  40. if (isset($options['Yii'])) {
  41. if ($label === false) {
  42. $this->parts['{label}'] = '';
  43. return $this;
  44. }
  45. $options = array_merge(['class' => 'search_name'], $options);
  46. if ($label !== null) {
  47. $options['label'] = $label;
  48. }
  49. if ($this->_skipLabelFor) {
  50. $options['for'] = null;
  51. }
  52. // $this->parts['{label}'] = Html::activeLabel($this->model, $this->attribute, $options);
  53. $this->parts['{label}'] = Html::tag('span', ($label === null ? $this->model->getAttributeLabel($this->attribute) : $label) . ':', $options);
  54. return $this;
  55. } else {
  56. return parent::label($label, $options);
  57. }
  58. }
  59. }