Пожалуйста, помогите разобраться с модулем от https://www.yiiframework.com/extension/ ... 2-treeview
При подключении модуля, как указано в инструкции пользования, получаю ошибку, хотя от автора указано что свойство по умолчанию 0:
Getting unknown property: common\models\Test::depth
Код: Выделить всё
www/vendor/koperdog/yii2-treeview/base/TreeHelper.php at line 66– yii\db\BaseActiveRecord::__get('depth')
Код: Выделить всё
$tree = [];
foreach ($models as $n) {
$node = &$tree;
for ($depth = $models[0]->depth; $n->depth > $depth; $depth++) {
$node = &$node[count($node) - 1]->children;
}
$n->children = null;
$node[] = $n;
}
Код: Выделить всё
<?php
namespace common\models;
use Yii;
class Test extends \yii\db\ActiveRecord
{
public $children = null;
public static function tableName()
{
return '{{%test}}';
}
public function rules()
{
return [
[['name'], 'required'],
[['parent_id', 'created_at'], 'integer'],
[['name'], 'string', 'max' => 250],
[['name'], 'unique'],
];
}
public function attributeLabels()
{
return [
'id' => Yii::t('app', 'ID'),
'name' => Yii::t('app', 'NAME'),
'parent_id' => Yii::t('app', 'PARENT'),
'created_at' => Yii::t('app', 'CREATED_AT'),
];
}
}
Код: Выделить всё
<?php
namespace common\models;
use yii\base\Model;
use yii\data\ActiveDataProvider;
use common\models\Test;
class TestSearch extends Test
{
public function rules()
{
return [
[['id', 'parent_id', 'created_at'], 'integer'],
[['name'], 'safe'],
];
}
public function scenarios()
{
return Model::scenarios();
}
public function search($params)
{
$query = Test::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
'pagination' => [
'pageSize' => 10,
],
]);
$this->load($params);
if (!$this->validate()) {
return $dataProvider;
}
$query->andFilterWhere([
'id' => $this->id,
'parent_id' => $this->parent_id,
'created_at' => $this->created_at,
]);
$query->andFilterWhere(['like', 'name', $this->name]);
return $dataProvider;
}
}
Код: Выделить всё
<?php
use koperdog\yii2treeview\TreeView;
$this->title = Yii::t('app', 'Tests');
$this->params['breadcrumbs'][] = $this->title;
?>
<div class="test-index">
<?= TreeView::widget([
'dataProvider' => $dataProvider,
'filterModel' => $searchModel,
//'depthPrefix' => ' - ', //see Additional options
//'depthRoot' => 0, //see Additional options
//'collaplse' => true, //see Additional options
'columns' => [
'id',
'name',
],
]); ?>
</div>