Browse Source

Revert "Fixed #11973: `yii\helpers\BaseHtml::getAttributeValue()` fixed to work with `items[]` notation correctly"

This reverts commit 3fcc26996b.
tags/2.0.10
SilverFire - Dmitry Naumenko 8 years ago
parent
commit
c66b845f48
  1. 2
      framework/helpers/BaseHtml.php
  2. 15
      tests/framework/helpers/HtmlTest.php

2
framework/helpers/BaseHtml.php

@ -2043,7 +2043,7 @@ class BaseHtml
} }
$attribute = $matches[2]; $attribute = $matches[2];
$value = $model->$attribute; $value = $model->$attribute;
if ($matches[3] !== '' && $matches[3] !== '[]') { if ($matches[3] !== '') {
foreach (explode('][', trim($matches[3], '[]')) as $id) { foreach (explode('][', trim($matches[3], '[]')) as $id) {
if ((is_array($value) || $value instanceof \ArrayAccess) && isset($value[$id])) { if ((is_array($value) || $value instanceof \ArrayAccess) && isset($value[$id])) {
$value = $value[$id]; $value = $value[$id];

15
tests/framework/helpers/HtmlTest.php

@ -1026,21 +1026,6 @@ EOD;
$noCsrfForm = Html::beginForm('/index.php', 'post', ['csrf' => false, 'id' => 'myform']); $noCsrfForm = Html::beginForm('/index.php', 'post', ['csrf' => false, 'id' => 'myform']);
$this->assertEquals('<form id="myform" action="/index.php" method="post">', $noCsrfForm); $this->assertEquals('<form id="myform" action="/index.php" method="post">', $noCsrfForm);
} }
public function testGetAttributeValue()
{
$model = new HtmlTestModel();
$model->types = ['type1', 'type2', ['sub-array', 'sub-array2']];
$this->assertEquals($model->types, Html::getAttributeValue($model, 'types'));
$this->assertEquals($model->types, Html::getAttributeValue($model, 'types[]'));
$this->assertEquals('type1', Html::getAttributeValue($model, 'types[0]'));
$this->assertEquals('type2', Html::getAttributeValue($model, 'types[1]'));
$this->assertEquals('type2', Html::getAttributeValue($model, 'types[1][]'));
$this->assertEquals(['sub-array', 'sub-array2'], Html::getAttributeValue($model, 'types[2][]'));
$this->assertEquals('sub-array2', Html::getAttributeValue($model, 'types[2][1]'));
$this->assertEquals(null, Html::getAttributeValue($model, 'types[3]'));
}
} }
/** /**

Loading…
Cancel
Save