Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jun 9, 2018
1 parent 27690f7 commit 39d4efd
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/IHasModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public function getModel();
* @param Model|ActiveRecord|Component|Object $model
* @return mixed
*/
public function setModel(BaseObject $model);
public function setModel($model);

}
22 changes: 17 additions & 5 deletions src/widgets/GridView.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
use skeeks\yii2\form\fields\FieldSet;
use skeeks\yii2\form\fields\SelectField;
use skeeks\yii2\form\fields\WidgetField;
use yii\base\Component;
use yii\base\Event;
use yii\base\Model;
use yii\data\ActiveDataProvider;
Expand Down Expand Up @@ -310,6 +311,11 @@ public function init()
if (!$this->dataProvider) {
$this->dataProvider = $this->_createDataProvider();
}

if (is_callable($this->dataProvider)) {
$callable = $this->dataProvider;
$this->dataProvider = call_user_func($callable, $this);
}
//Автомтическое конфигурирование колонок
$this->_initAutoColumns();

Expand Down Expand Up @@ -497,15 +503,15 @@ protected function _initAutoColumns()
$keyName = lcfirst(Inflector::id2camel($key, '_'));
$keyManyName = lcfirst(Inflector::id2camel($keyMany, '_'));

if ($model->hasProperty($keyName)) {
if ($model instanceof Component && $model->hasProperty($keyName)) {
$this->_autoColumns[(string)$name] = [
'attribute' => $name,
'format' => 'raw',
'value' => function ($model, $key, $index) use ($name, $keyName) {
return $model->{$keyName};
},
];
} else if ($model->hasProperty(lcfirst($keyManyName))) {
} else if ($model instanceof Component && $model->hasProperty(lcfirst($keyManyName))) {
$this->_autoColumns[(string)$name] = [
'attribute' => $name,
'format' => 'raw',
Expand All @@ -518,10 +524,16 @@ protected function _initAutoColumns()
'attribute' => $name,
'format' => 'raw',
'value' => function ($model, $key, $index) use ($name) {
if (is_array($model->{$name})) {
return implode(",", $model->{$name});
if (is_array($model)) {
$v = $model[$name];
} else {
$v = $model->{$name};
}

if (is_array($v)) {
return implode(",", $v);
} else {
return $model->{$name};
return $v;
}
},
];
Expand Down

0 comments on commit 39d4efd

Please sign in to comment.