| Total Complexity | 6 |
| Total Lines | 27 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 18 | class Html extends H |
||
| 19 | { |
||
| 20 | /** |
||
| 21 | * 获取 input 值 |
||
| 22 | * |
||
| 23 | * @param yii\base\Model $model 模型对象 |
||
| 24 | * @param string $attribute |
||
| 25 | * @param mixed $formName |
||
| 26 | * |
||
| 27 | * @return string |
||
| 28 | */ |
||
| 29 | public static function getInputName($model, $attribute, $formName = null) |
||
| 30 | { |
||
| 31 | $formName = null === $formName ? $model->formName() : $formName; |
||
| 32 | if (!preg_match(static::$attributeRegex, $attribute, $matches)) { |
||
| 33 | throw new InvalidArgumentException('Attribute name must contain word characters only.'); |
||
| 34 | } |
||
| 35 | $prefix = $matches[1]; |
||
| 36 | $attribute = $matches[2]; |
||
| 37 | $suffix = $matches[3]; |
||
| 38 | if ($formName === '' && $prefix === '') { |
||
| 39 | return $attribute . $suffix; |
||
| 40 | } elseif ($formName !== '') { |
||
| 41 | return $formName . $prefix . '[' . $attribute . ']' . $suffix; |
||
| 42 | } |
||
| 43 | |||
| 44 | throw new InvalidArgumentException(get_class($model) . '::formName() cannot be empty for tabular inputs.'); |
||
| 45 | } |
||
| 47 |