Skip to content

Commit 122c0ed

Browse files
author
Eugene Tupikov
committed
add support of DynamicModel
1 parent 7779c7f commit 122c0ed

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

src/MultipleInputColumn.php

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
use yii\base\InvalidConfigException;
1212
use yii\base\Model;
13+
use yii\base\DynamicModel;
1314
use yii\db\ActiveRecordInterface;
1415
use yii\helpers\Html;
1516
use unclead\multipleinput\components\BaseColumn;
@@ -40,13 +41,14 @@ public function init()
4041
/**
4142
* Returns element's name.
4243
*
43-
* @param int|null $index current row index
44+
* @param int|null|string $index current row index
4445
* @param bool $withPrefix whether to add prefix.
46+
*
4547
* @return string
4648
*/
4749
public function getElementName($index, $withPrefix = true)
4850
{
49-
if (is_null($index)) {
51+
if ($index === null) {
5052
$index = '{' . $this->renderer->getIndexPlaceholder() . '}';
5153
}
5254

@@ -99,11 +101,17 @@ protected function hasModelAttribute($name)
99101

100102
if ($model->hasProperty($name)) {
101103
return true;
102-
} elseif ($model instanceof ActiveRecordInterface && $model->hasAttribute($name)) {
104+
}
105+
106+
if ($model instanceof ActiveRecordInterface && $model->hasAttribute($name)) {
103107
return true;
104-
} else {
105-
return false;
106108
}
109+
110+
if ($model instanceof DynamicModel && isset($model->{$name})) {
111+
return true;
112+
}
113+
114+
return false;
107115
}
108116

109117
/**

src/TabularColumn.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,13 +25,13 @@ class TabularColumn extends BaseColumn
2525
/**
2626
* Returns element's name.
2727
*
28-
* @param int|null $index current row index
28+
* @param int|null|string $index current row index
2929
* @param bool $withPrefix whether to add prefix.
3030
* @return string
3131
*/
3232
public function getElementName($index, $withPrefix = true)
3333
{
34-
if (is_null($index)) {
34+
if ($index === null) {
3535
$index = '{' . $this->renderer->getIndexPlaceholder() . '}';
3636
}
3737

0 commit comments

Comments
 (0)