Skip to content

Commit d3b0b3d

Browse files
committed
Get data from a model only if an attribute exists
1 parent dcbd345 commit d3b0b3d

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

src/MultipleInput.php

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

1111
use Yii;
1212
use yii\base\Model;
13+
use yii\helpers\ArrayHelper;
1314
use yii\widgets\InputWidget;
1415
use yii\db\ActiveRecordInterface;
1516
use unclead\widgets\renderers\TableRenderer;
@@ -127,7 +128,10 @@ protected function initData()
127128
}
128129

129130
if ($this->model instanceof Model) {
130-
foreach ((array)$this->model->{$this->attribute} as $index => $value) {
131+
$data = $this->model->hasProperty($this->attribute)
132+
? ArrayHelper::getValue($this->model, $this->attribute, [])
133+
: [];
134+
foreach ((array) $data as $index => $value) {
131135
$this->data[$index] = $value;
132136
}
133137
}

0 commit comments

Comments
 (0)